Hide

Problem F
Chinese Remainder

Input

The first line of input consists of an integers T where 1T1000, the number of test cases. Then follow T lines, each containing four integers a, n, b, m satisfying 1n,m109, 0a<n, 0b<m. Also, you may assume gcd(n,m)=1.

Output

For each test case, output two integers x, K, where K=nm and 0x<K, giving the solution x(modK) to the equations x=a(modn),x=b(modm).

Sample Input 1 Sample Output 1
2
1 2 2 3
151 783 57 278
5 6
31471 217674
Hide

Please log in to submit a solution to this problem

Log in