#418. Necklace of Beads
Necklace of Beads
Description
Beads of red, blue or green colors are connected together into a circular necklace of beads. If the repetitions that are produced by rotation around the center of the circular necklace are all neglected, the green beads appear no more than times, and all adjacent beads are of different colors, how many different forms of the necklace are there?
Format
Input
The first line contains an integer representing the number of test cases.
For each test case, there are two integers in one line.
It is guaranteed that .
Output
For each test case, print a line with an integer, representing the answer, modulo .
Samples
3
3 1
4 1
10 3
2
3
58