#YSS82. 公倍佩尔数-Metric times Pell number
公倍佩尔数-Metric times Pell number
At midnight, I dare not look back when crossing the overpass, where it used to be bustling with traffic, now lies the River of Forgetfulness under my feet.
--- Out of the Mountains
Problem Description
Given two positive integers and , where is a prime number, it is guaranteed that for all positive integers , can be expressed as , where and are integers, and is not zero modulo . Obviously, . Let .
Given and , calculate the value of modulo .
Input Format
- The first line contains a positive integer , representing the number of test cases.
- The next lines each contain two positive integers and .
Output Format
For each test case, output a single non-negative integer representing the answer for that test case.
Sample Input
5
1 233
2 233
3 233
4 233
5 233
Sample Output
1
5
35
42
121
Hints
Data Size and Constraints
For 100% of the data, , , , .