In 1960, Donald Wall, who worked at IBM, proved that the remainders of the Fibonacci numbers modulo m form a repeating cycle.
For example, the first 10 Fibonacci numbers and their remainders modulo 11 are shown below.
| n | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| F(n) | 1 | 1 | 2 | 3 | 5 | 8 | 13 | 21 | 34 | 55 |
| F(n)mod11 | 1 | 1 | 2 | 3 | 5 | 8 | 2 | 10 | 1 | 0 |
The sequence of remainders repeats the same block over and over. Writing k(m) for the length of that repeating block, k(11)=10.
Wall proved several other properties.
Given m, write a program that computes k(m).
The first line contains the number of test cases P.
Each of the next P lines contains two integers N and M separated by a single space. N is the number of the test case and M is the m described above.
For each test case, print the test case number N and k(M) on one line, separated by a single space. Keep the order in which the test cases were given.