#nt301. 中国剩余定理
中国剩余定理
Chinese Remainder Theorem
Problem Description
There are test cases. For each case you are given equations and must find such that for every .
Input Format
The first line contains an integer .
For each test case, the first line contains an integer , and the following lines each contain two integers .
Output Format
For each test case, output one integer: the answer. The answer must lie in the range to . The data guarantees that a solution exists.
Sample Input
1
3
1 10
2 11
3 12
Sample Output
651
Constraints
, , . It is guaranteed that does not exceed .