Exciting Bets
Contest: Codeforces Round 730 (Div. 2)
Difficulty rating: 900
Tags: greedy, math, number theory

Welcome to Rockport City!

It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet $$$a$$$ dollars and Ronnie has bet $$$b$$$ dollars. But the fans seem to be disappointed. The excitement of the fans is given by $$$gcd(a,b)$$$, where $$$gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$. To make the race more exciting, you can perform two types of operations:

1. Increase both $$$a$$$ and $$$b$$$ by $$$1$$$.
2. Decrease both $$$a$$$ and $$$b$$$ by $$$1$$$. This operation can only be performed if both $$$a$$$ and $$$b$$$ are greater than $$$0$$$.

In one move, you can perform any one of these operations. You can perform arbitrary (possibly zero) number of moves. Determine the maximum excitement the fans can get and the minimum number of moves required to achieve it.

Note that $$$gcd(x,0)=x$$$ for any $$$x \ge 0$$$.

Input format:
The first line of input contains a single integer $$$t$$$ ($$$1\leq t\leq 5\cdot 10^3$$$) — the number of test cases.

The first and the only line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$0\leq a, b\leq 10^{18}$$$).

Output format:
For each test case, print a single line containing two integers.

If the fans can get infinite excitement, print 0 0.

Otherwise, the first integer must be the maximum excitement the fans can get, and the second integer must be the minimum number of moves required to achieve that excitement.

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Note:
For the first test case, you can apply the first operation $$$1$$$ time to get $$$a=9$$$ and $$$b=6$$$. It can be shown that $$$3$$$ is the maximum excitement possible.

For the second test case, no matter how many operations you apply, the fans will always have an excitement equal to $$$1$$$. Since the initial excitement is also $$$1$$$, you don't need to apply any operation.

For the third case, the fans can get infinite excitement by applying the first operation an infinite amount of times.

For the fourth test case, you can apply the second operation $$$3$$$ times to get $$$a=0$$$ and $$$b=6$$$. Since, $$$gcd(0,6)=6$$$, the fans will get an excitement of $$$6$$$.

Example input:
4
8 5
1 2
4 4
3 9

Example output:
3 1
1 0
0 0
6 3

Editorial:
If $$$a=b$$$, the fans can get an infinite amount of excitement, and we can achieve this by applying the first operation infinite times.
Otherwise, the maximum excitement the fans can get is $$$g=\lvert a-b\rvert$$$ and the minimum number of moves required to achieve it is $$$min(a\bmod g,g-a\bmod g)$$$.
Proof -
Without loss of generality, assume $$$a>b$$$ otherwise we can swap $$$a$$$ and $$$b$$$. We know that $$$GCD(a,b) = GCD(a-b,b)$$$. Notice that no matter how many times we apply any operation, the value of $$$a-b$$$ does not change. We can arbitrarily change the value of $$$b$$$ to a multiple of $$$a-b$$$ by applying the operations. In this way, we can achieve a GCD of $$$a-b$$$. Now, since $$$GCD(x,y)\leq min(x,y)$$$, $$$GCD(a-b,b)$$$ can never exceed $$$a-b$$$. So, we cannot achieve a higher GCD by any means.
To achieve the required GCD, we need to make $$$b$$$ a multiple of $$$g=a-b$$$. There are two ways to do so  — decrease $$$b$$$ to the largest multiple of $$$g$$$ less than or equal to $$$b$$$ or increase $$$b$$$ to the smallest multiple of $$$g$$$ greater than $$$b$$$. The number of operations required to do so are $$$b\bmod g$$$ and $$$g-b\bmod g$$$ respectively. We will obviously choose the minimum of the two. Also notice that $$$a\bmod g=b\bmod g$$$ since $$$a=b+g$$$. So, it doesn't matter if we use either $$$a$$$ or $$$b$$$ to determine the minimum number of operations.
Time Complexity - $$$\mathcal{O}(1)$$$ per test case.