Start

2018-05-21 00:00 UTC

CFT15

End

2018-05-22 00:00 UTC
The end is near!
Contest is over.
Not yet started.
Contest is starting in -489 days 14:00:46

Time elapsed

24:00:00

Time remaining

0:00:00

Problem C
Chinese Remainder

Input

The first line of input consists of an integers $T$ where $1 \leq T \leq 1000$, the number of test cases. Then follow $T$ lines, each containing four integers $a$, $n$, $b$, $m$ satisfying $1 \leq n, m \leq 10^9$, $0 \leq a < n$, $0 \leq b < m$. Also, you may assume $\mbox{gcd}(n, m) = 1$.

Output

For each test case, output two integers $x$, $K$, where $K = nm$ and $0 \leq x < K$, giving the solution $x \pmod K$ to the equations $x = a \pmod n, x = b \pmod m$.

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