Today Oz has an interesting problem for you. Oz has a set of M balls numbered from 0 to M-1. He has removed X balls from the set and calculated the sum of the numbers of removed balls. He has given you a hint that the sum is divisible by M.
Now your task is to count the number of ways of removing X balls. Output the answer modulo 109+7.
Input:
First line contains one integer T - number of test cases.
Each test case contains two space separated integers M and X.
Output:
For each test case output the desired answer modulo 109+7.
Constraints:
1 ≤ T ≤ 10
1 ≤ M ≤ 109
1 ≤ X ≤ 105
X ≤ M
7 balls are numbered from 0 to 6 and 4 of them are removed. Possible removals are {0, 3, 5, 6}, {1, 2, 5, 6}, {2, 3, 4, 5}, {0, 1, 2, 4}, {1, 3, 4, 6}.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor