{"trustable":true,"sections":[{"title":"","value":{"format":"MD","content":"![Necklace][1]\nYou are a necklace maker. You like this task because it\u0027s challenging, fascinating and of course makes a lot of money. Now, you want to make a necklace consisting of **n** beads. The beads are connected in the following fashion:\n\n1. Bead **i (1 \u0026lt; i \u0026lt; n)** is connected with bead **i - 1** and bead **i + 1**.\n2. The first bead is connected with the second bead and the **n\u003csup\u003eth\u003c/sup\u003e** bead.\n3. The **n\u003csup\u003eth\u003c/sup\u003e** bead is connected with the first bead and the **(n-1)\u003csup\u003eth\u003c/sup\u003e** bead.\n \nNow you have **K** colors and each bead can be colored using one of the **K** colors. You have to find the number of possible necklaces you can make using these colors. Two necklaces will be considered same if one can be rotated to another.\n\nFor example, say there are 4 beads in the necklace and you have two colors yellow and green, then there are 6 possible necklaces. They are:\n\n\n\n| ![][2] | ![][3] | ![][4] | ![][5] | ![][6] | ![][7] |\n| ------ | ------ | ------ | ------ | ------ | ------ |\n\n\n\n[1]: https://static.lightoj.com/images/problem-1419/necklace1-1602925531708.png?rightme\n[2]: https://static.lightoj.com/images/problem-1419/necklace2-1602925827643.png\n[3]: https://static.lightoj.com/images/problem-1419/necklace3-1602925926983.png\n[4]: https://static.lightoj.com/images/problem-1419/necklace4-1602925981308.png\n[5]: https://static.lightoj.com/images/problem-1419/necklace5-1602926028944.png\n[6]: https://static.lightoj.com/images/problem-1419/necklace6-1602926068704.png\n[7]: https://static.lightoj.com/images/problem-1419/necklace7-1602926104139.png"}},{"title":"Input","value":{"format":"MD","content":"Input starts with an integer **T (\u0026le; 50)**, denoting the number of test cases.\n\nEach case starts with a line containing two integers: **n** and **K (1 \u0026le; n \u0026le; 1000, 1 \u0026le; K \u0026le; 10\u003csup\u003e9\u003c/sup\u003e)**."}},{"title":"Output","value":{"format":"MD","content":"For each case, print the case number and the total number of possible necklaces modulo **1000000007 (10\u003csup\u003e9\u003c/sup\u003e + 7)**."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e7\n4 2\n5 7\n5 2\n4 8\n4 3\n5 3\n5 5\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1: 6\nCase 2: 3367\nCase 3: 8\nCase 4: 1044\nCase 5: 24\nCase 6: 51\nCase 7: 629\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}