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:

Increase both $a$ and $b$ by $1$.

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-----

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-----

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.


-----Examples-----

Input
4
8 5
1 2
4 4
3 9
Output
3 1
1 0
0 0
6 3


-----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$.

Source: codeforces | Difficulty: EASY
Tags: Number theory

Mathematics

Greedy algorithms


Solutions:
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	s = abs(a - b)
	m = 0
	if s != 0:
		m = a % s
	print(s, min(m, s - m))


import math

def solve():
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	x = abs(b - a)
	if a == b:
		print(0, 0)
	elif a == 0:
		print(x, 0)
	else:
		print(x, min(a % x, x - a % x))
t = int(input())
for _ in range(t):
	solve()


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	d = abs(a - b)
	if d == 0:
		print(0, 0)
		continue
	minus_count = a % d
	plus_count = d - minus_count
	if min(a, b) - minus_count < 0:
		print(d, plus_count)
		continue
	if minus_count < plus_count:
		print(d, minus_count)
	else:
		print(d, plus_count)


for a0 in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	v = abs(a - b)
	if v == 0:
		print(0, 0)
	else:
		if a > b:
			m = b
		else:
			m = a
		v1 = m % v
		if v1 > v - v1:
			v1 = v - v1
		print(v, v1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
		continue
	(a, b) = sorted([a, b])
	k = b - a
	print(k, min(b % k, k - b % k, a))


import sys

def input():
	return sys.stdin.readline().rstrip()
from math import gcd

def main():
	t = int(input())
	for i in range(t):
		(a, b) = map(int, input().split())
		if a == b:
			print(0, 0)
		else:
			d = abs(a - b)
			r = a % d
			if r == 0:
				print(d, 0)
			else:
				print(d, min(r, d - r))
	return 0
main()


import random
import collections
import string
import math
import copy
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
mo = int(1000000000.0 + 7)

def exgcd(a, b):
	if not b:
		return (1, 0)
	(y, x) = exgcd(b, a % b)
	y -= a // b * x
	return (x, y)

def getinv(a, m):
	(x, y) = exgcd(a, m)
	return -1 if x == 1 else x % m

def comb(n, b):
	res = 1
	b = min(b, n - b)
	for i in range(b):
		res = res * (n - i) * getinv(i + 1, mo) % mo
	return res % mo

def quickpower(a, n):
	res = 1
	while n:
		if n & 1:
			res = res * a % mo
		n >>= 1
		a = a * a % mo
	return res

def quickpowerm(a, n, mo):
	res = 1
	while n:
		if n & 1:
			res = res * a % mo
		n >>= 1
		a = a * a % mo
	return res

def dis(a, b):
	return abs(a[0] - b[0]) + abs(a[1] - b[1])

def getpref(x):
	if x > 1:
		return x * (x - 1) >> 1
	else:
		return 0

def orafli(upp):
	primes = []
	marked = [False for i in range(upp + 3)]
	prvs = [i for i in range(upp + 3)]
	for i in range(2, upp):
		if not marked[i]:
			primes.append(i)
		for j in primes:
			if i * j >= upp:
				break
			marked[i * j] = True
			prvs[i * j] = j
			if i % j == 0:
				break
	return (primes, prvs)

def lower_ord(c: str) -> int:
	return ord(c) - 97

def upper_ord(c: str) -> int:
	return ord(c) - 65

def read_list():
	return [int(i) for i in input().split()]

def read_int():
	s = input().split()
	if len(s) == 1:
		return int(s[0])
	else:
		return map(int, s)

def ask(s):
	print(f'? {s}', flush=True)

def answer(s):
	print(f'{s}', flush=True)
import functools
import itertools
from fractions import Fraction

def solve():
	(a, b) = read_int()
	if a == b:
		print(0, 0)
		return
	dvd = abs(a - b)
	am = a % dvd
	ans2 = min(am, dvd - am)
	print(dvd, ans2)
T = int(input())
for ti in range(T):
	solve()


import sys
lines = sys.stdin.read().strip().split('\n')
for line in lines[1:]:
	(a, b) = map(int, line.strip().split())
	if b < a:
		(a, b) = (b, a)
	if a == b:
		print('0 0')
	else:
		dif = b - a
		r = a % dif
		move = r if r * 2 < dif else dif - r
		print(f'{dif} {move}')


import sys
import math

def read_ints():
	inp = input().split()
	inp = [int(x) for x in inp]
	return inp

def read_strings():
	inp = input().split()
	s = [inp[i] for i in range(len(inp))]
	return s
t = int(input())
for _ in range(t):
	ab = read_ints()
	a = ab[0]
	b = ab[1]
	maxe = 0
	minm = 0
	if a == b:
		maxe = 0
		minm = 0
	else:
		maxe = abs(a - b)
		minm = min(a % maxe, maxe - a % maxe)
	ans = str(maxe) + ' ' + str(minm)
	print(ans)


T = int(input().strip())
for cas in range(T):
	(x, y) = map(int, input().strip().split())
	if x == y:
		print('0 0')
		continue
	if x < y:
		(x, y) = (y, x)
	print('%d %d' % (x - y, min(y % (x - y), x - y - y % (x - y))))


t = int(input())
for case in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
		continue
	ex = abs(a - b)
	moves = min(a % ex, ex - a % ex)
	print(ex, moves)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if x == y:
		print(0, 0)
	elif x != y:
		common_divisor = abs(x - y)
		count = x % common_divisor
		temp_answer = min(count, common_divisor - count)
		print(common_divisor, temp_answer)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print('0', '0')
	else:
		diff = max(a, b) - min(a, b)
		print(diff, end=' ')
		print(min(a % diff, diff - a % diff))


t = int(input())
for i in range(0, t):
	(a, b) = map(int, input().split())
	if a != b:
		c = abs(a - b)
		r = a % c
		print(c, min(r, c - r))
	else:
		print(0, 0)


import math
for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a == b:
		print('0', '0')
	else:
		g = abs(a - b)
		print(g, min(a % g, (g - a) % g))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	else:
		Max = abs(a - b)
		Min = min(a % Max, (Max - a) % Max)
		print(Max, Min)


num = int(input())
for i in range(num):
	arr = input().split()
	a = int(arr[0])
	b = int(arr[1])
	m = abs(a - b)
	n = 0
	if m != 0:
		n = a % m
	print(m, min(n, m - n))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	else:
		h = abs(b - a)
		k = min(a, b) % abs(b - a)
		if k > h // 2:
			k = h - k
		print(h, k)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(a, b) = map(int, stdin.readline().strip().split())
	if a == b:
		stdout.write('0 0\n')
	else:
		diff = abs(a - b)
		lower = min(a, b) % diff
		upper = diff - lower
		stdout.write(str(diff) + ' ' + str(min(lower, upper)) + '\n')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	x = min(a, b)
	y = max(a, b)
	if x == y:
		print('0 0')
	else:
		print(y - x, end=' ')
		b = y - x
		a = x % b
		print(min(a, b - a))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	r = abs(a - b)
	s = 0
	if a == b:
		print(0, 0)
	else:
		print(r, min(r - a % r, a % r))


import sys
from sys import stdin, stdout
from math import ceil, floor, sqrt, log, log2, log10
from collections import Counter
int_max = float('inf')
int_min = -float('inf')
ANS = []
input = stdin.readline

def solve():
	pass
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	else:
		print(abs(a - b), min(a % abs(a - b), abs(a - b) - a % abs(a - b)))
print('\n'.join(ANS))


test = int(input())
for _ in range(test):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
		continue
	gcd = abs(a - b)
	rem = max(a, b) % gcd
	print(gcd, min(rem, gcd - rem))


import math
import os
import sys
from math import ceil, floor, sqrt, gcd, factorial
from io import BytesIO, IOBase
from collections import Counter
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def prog_name():
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	else:
		g = abs(a - b)
		ans = max(a, b) % g
		print(abs(a - b), min(min(ans, g - ans), min(a, b)))

def main():
	T = int(input())
	for unique in range(T):
		prog_name()
main()


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(n, m) = map(int, sys.stdin.readline().split())
	if n == m:
		print(0, 0)
	else:
		a = abs(n - m)
		if n % a:
			(x, y) = (min(n % a, a - n % a), min(m % a, a - m % a))
			print(a, min(x, y))
		else:
			print(a, 0)


import sys
from math import ceil, floor, modf, sqrt
from collections import deque

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(get_ints())

def input():
	return sys.stdin.readline().strip()

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
T = int(input())
while T > 0:
	(x, y) = get_ints()
	diff = abs(x - y)
	if diff == 0:
		print(0, 0)
		T -= 1
		continue
	a1 = x % diff
	a2 = y % diff
	print(diff, min(diff - a1, a1))
	T -= 1


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a < b:
		(a, b) = (b, a)
	ans = a - b
	if ans == 0:
		print(0, 0)
		continue
	ans2 = min(ans - b % ans, b % ans)
	print(ans, ans2)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	flag = True
	if a == b:
		flag = 'Red'
	elif a < b:
		ans = b - a
		x = a % ans
		y = ans - a % ans
		c = min(x, y)
	else:
		ans = a - b
		x = b % ans
		y = ans - b % ans
		c = min(x, y)
	if flag == 'Red':
		print(0, 0)
	else:
		print(ans, c)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print('0 0')
	else:
		ans1 = abs(a - b)
		ans2 = min(ans1 - a % ans1, a % ans1)
		print(ans1, ans2)


n = int(input())
l2 = []
for i in range(n):
	l2.append([int(x) for x in input().split()])
for i in range(n):
	a = l2[i][0]
	b = l2[i][1]
	if a == b:
		print(0, 0)
	elif abs(a - b) == 1:
		print(1, 0)
	elif min(a, b) == 0:
		print(max(a, b), 0)
	else:
		c = abs(a - b)
		if a % c == b % c:
			print(c, min(c - a % c, a % c))
print()


import math

def main():
	t = int(input())
	while t > 0:
		t -= 1
		(a, b) = map(int, input().split())
		dif = abs(a - b)
		if a == b:
			print('0 0')
			continue
		i = 0
		aux = max(a, b) / dif
		sig = (int(aux) + 1) * dif if aux - int(aux) > 0.5 else int(aux) * dif
		print(f'{dif} {abs(sig - max(a, b))}')
main()


import sys, math
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b == a:
		print(0, 0)
	elif b > a:
		print(b - a, min(b - a - a % (b - a), a % (b - a)))
	else:
		b = a ^ b
		a = a ^ b
		b = a ^ b
		print(b - a, min(b - a - a % (b - a), a % (b - a)))


t = int(input())
for _ in range(t):
	(x, y) = [int(x) for x in input().split(' ')]
	(a, b) = (min(x, y), max(x, y))
	if b == a:
		print(0, 0)
	elif a * b == 0:
		print(b, 0)
	else:
		print(b - a, min(a % (b - a), b - a - a % (b - a)))


t = int(input())
for i in range(t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	gcd = 0
	if a > b:
		gcd = a - b
	else:
		gcd = b - a
	if a == b:
		print('0  0')
	elif gcd == 1:
		print('1  0')
	else:
		m = a % gcd
		if m == 0:
			print(gcd, m)
		else:
			m1 = m
			n = gcd - m
			if m1 > n:
				m = n
			else:
				m = m1
			print(gcd, m)


import sys

def ints():
	return list(map(int, sys.stdin.readline().strip().split()))
tc = int(input())
while tc:
	tc -= 1
	(n, m) = map(int, input().split())
	if abs(n - m) == 0:
		print(0, 0)
		continue
	print(abs(n - m), min(abs(n - m) - min(n, m) % abs(n - m), min(n, m) % abs(n - m)))


t = int(input())
ans = []
for i in range(t):
	ip = input()
	ip = ip.split(' ')
	(x, y) = (int(ip[0]), int(ip[1]))
	(x1, y1) = (x, y)
	gcd = abs(x - y)
	if gcd == 0:
		ans.append('{} {}'.format(0, 0))
		continue
	c = 0
	mul = int(x / gcd)
	ans.append('{} {}'.format(gcd, min(abs(gcd * mul - x), abs(gcd * (mul + 1) - x))))
for i in range(t):
	print(ans[i])


from math import *
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	else:
		g = abs(a - b)
		m = min(a % g, g - a % g)
		print(g, m)


from sys import stdin, setrecursionlimit, maxsize
from collections import deque
from math import gcd
input = stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	else:
		g = abs(a - b)
		m = min(a % g, g - a % g)
		print(g, m)


import sys
import math
lines = []
is_stdin = False
is_stdin = True
if is_stdin:
	for line in sys.stdin:
		lines.append(line.strip())
else:
	with open('./myin.txt', 'r') as f:
		for line in f.readlines():
			lines.append(line.strip())
N = int(lines.pop(0))

def gcd(a, b):
	if b == 0:
		return a
	a %= b
	return gcd(b, a)
while N > 0:
	N -= 1
	n = lines.pop(0)
	pieces = n.split(' ')
	a = pieces[0]
	b = pieces[1]
	a = int(a)
	b = int(b)
	if a == b:
		print('0 0')
		continue
	if a < b:
		tmp = a
		a = b
		b = tmp
	excite = a - b
	left = b // excite
	right = left + 1
	left_b = left * excite
	right_b = right * excite
	moves = min(b - left_b, right_b - b)
	print('{} {}'.format(excite, moves))


from math import *
n = int(input(''))
A = []
B = []
for i in range(n):
	(a, b) = input('').split(' ')
	(a, b) = (int(a), int(b))
	A.append(a)
	B.append(b)
for i in range(n):
	a = A[i]
	b = B[i]
	d = abs(a - b)
	if d == 1:
		print('1 0')
	elif d == 0:
		print('0 0')
	elif a % d != 0:
		ad = floor(a / d) * d
		au = ceil(a / d) * d
		print(d, min(abs(ad - a), abs(au - a)))
	else:
		print(d, ' ', 0)


import math
from sys import stdin, stdout
from collections import defaultdict, Counter, deque
for _ in range(int(stdin.readline())):
	(a, b) = map(int, stdin.readline().split())
	if a == b:
		print('0 0')
	elif abs(a - b) == 1:
		print('1 0')
	else:
		gc = abs(a - b)
		if a > b:
			(a, b) = (b, a)
		print(gc, min(abs(gc - a % gc), a % gc))


t = int(input())
results = []
for i in range(t):
	(a, b) = map(int, input().split())
	if a > b:
		res = a - b
		current = b % res
	elif a < b:
		res = b - a
		current = a % res
	if a != b:
		if current > res - current:
			results.append((res, res - current))
		else:
			results.append((res, current))
	else:
		results.append((0, 0))
for i in range(t):
	print(results[i][0], results[i][1])


import math
from sys import stdin

def A():
	t = int(stdin.readline())
	while t:
		t -= 1
		d = [int(x) for x in stdin.readline().split()]
		(a, b) = (d[0], d[1])
		gcd = math.gcd(a, b)
		if gcd == a == b:
			print(0, end=' ')
			print(0)
		else:
			g = abs(a - b)
			m = min(a % g, g - a % g)
			print(g, end=' ')
			print(m)
A()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	else:
		dif = abs(a - b)
		mi = min(a, b)
		rem = mi % dif
		print(dif, min(rem, abs(dif - rem)))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print('0 0')
	elif abs(a - b) == 1:
		print('1 0')
	elif a == 0 and b != 0:
		print(str(b) + ' 0')
	elif b == 0 and a != 0:
		print(str(a) + ' 0')
	else:
		exc = abs(a - b)
		if a < b:
			k = 0
			while k < a:
				pre = k
				k = k + exc
			if a - pre > k - a:
				print(str(exc) + ' ' + str(k - a))
			else:
				print(str(exc) + ' ' + str(a - pre))
		else:
			k = 0
			while k < b:
				pre = k
				k = k + exc
			if b - pre > k - b:
				print(str(exc) + ' ' + str(k - b))
			else:
				print(str(exc) + ' ' + str(b - pre))


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007

def solve():
	pass
for _ in range(int(input())):
	(a, b) = get_int()
	if a == b:
		print(0, 0)
	else:
		diff = abs(a - b)
		m = a % diff
		print(diff, min(diff - m, m))


for run in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	else:
		excitment = abs(a - b)
		moves = min(a % excitment, excitment - a % excitment)
		print(excitment, moves)


def calc():
	(a, b) = list(map(int, input().split(' ')))
	if a == b:
		print('0 0')
		return
	d = abs(b - a)
	x = a % d
	y = d - x
	print('{0} {1}'.format(d, min([x, y])))
t = int(input())
for _i in range(t):
	calc()


from math import ceil
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	else:
		mgcd = max(a, b) - min(a, b)
		temp = min(a, b)
		x = ceil(temp / mgcd)
		z = temp // mgcd
		y = x * mgcd - temp
		y2 = temp - z * mgcd
		ans = min(temp, y, y2)
		print(mgcd, ans)


n = int(input())
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	best_gcd = abs(a - b)
	if best_gcd == 0:
		min_steps = 0
	else:
		target_1 = best_gcd * (a // best_gcd + 1) - a
		target_3 = a % best_gcd
		min_steps = min(target_1, target_3)
	print(best_gcd, min_steps)


N = int(input())
arr = []
arr = [[0 for j in range(2)] for i in range(N)]
for i in range(N):
	(a, b) = map(int, input().split())
	if a != b:
		dif = abs(a - b)
		mod1 = a % dif
		mod2 = dif - a % dif
		arr[i][0] = dif
		arr[i][1] = min(mod1, mod2)
for i in range(N):
	print(str(arr[i][0]) + ' ' + str(arr[i][1]))


import math
for i in range(int(input())):
	(a, b) = map(int, input().split())
	d = abs(a - b)
	f = min(a, b)
	if d == 0 or d == 1:
		e = 0
	else:
		g = math.ceil(f / d)
		l = f // d
		e = min(d * g - f, f - l * d)
	print(d, e)


import os, sys
from io import BytesIO, IOBase
from types import GeneratorType
from bisect import *
from collections import defaultdict, deque, Counter
import math, string
from heapq import *
from operator import add
from itertools import accumulate
BUFSIZE = 8192
sys.setrecursionlimit(10 ** 5)

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
inf = float('inf')
en = lambda x: list(enumerate(x))
ceil_ = lambda a, b: (a + b - 1) // b
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())

def solve():
	(a, b) = r()
	if a == b:
		print(0, 0)
		return
	x = abs(a - b)
	a = a % x
	print(x, min(a, x - a))
for _ in ' ' * ii():
	solve()


from math import ceil, floor

def main():
	import sys
	input = sys.stdin.readline
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		d = abs(a - b)
		if d > 0:
			m = abs(a - floor(a / d) * d) if abs(a - floor(a / d) * d) < abs(ceil(a / d) * d - a) else abs(ceil(a / d) * d - a)
			print(d, m)
		else:
			print(0, 0)
main()


import math
testcase = int(input())
results = []
for x in range(testcase):
	(a, b) = [int(j) for j in input().split()]
	if a == b:
		tup = (0, 0)
		results.append(tup)
	else:
		diff = abs(a - b)
		m = min(a % diff, diff - a % diff)
		tup = (diff, m)
		results.append(tup)
for o in results:
	stringlist = [str(k) for k in o]
	print(' '.join(stringlist))


import math
import sys

def scan():
	return list(map(int, sys.stdin.readline().strip().split()))

def solution():
	for _ in range(int(input())):
		(a, b) = scan()
		if a == b:
			print(0, 0)
		else:
			d = abs(a - b)
			print(d, min(a % d, (d - a) % d))
solution()


import math
from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, gcd
import bisect
import sys
import random
import heapq

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
for _ in range(int(input())):
	(a, b) = get_ints()
	if a == b:
		print(0, 0)
		continue
	max_ans = abs(b - a)
	k = max_ans - a % max_ans
	print(max_ans, min(a % max_ans, k))


x = []
t = int(input())
for ti in range(t):
	l = [int(l) for l in input().split()]
	x.append(l)
for j in range(t):
	a = x[j][0]
	b = x[j][1]
	d = 0
	if a > b:
		d = a - b
	else:
		d = b - a
	if d == 0:
		print('0 0')
		continue
	else:
		print(d, min(a % d, d - a % d))


t = int(input())
ret = []
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	if a == b:
		ret.append('0 0')
	else:
		if a < b:
			(a, b) = (b, a)
		d = a - b
		q = a // d
		v1 = q * d
		v2 = v1 + d
		mn = min(a - v1, v2 - a)
		ret.append(str(d) + ' ' + str(mn))
print('\n'.join(ret))


n = int(input())
for i in range(0, n):
	(a, b) = map(int, input().split())
	x = abs(a - b)
	if x == 0:
		print(0, 0)
	else:
		y = min(a % x, x - a % x)
		print(x, y)


import math
t = int(input())
while t:
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	else:
		g = abs(a - b)
		ans = min(a % g, g - a % g)
		print(g, ans)
	t -= 1


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	diff = abs(a - b)
	if a > b:
		print(diff, min(diff - a % diff, b % diff))
	elif b > a:
		print(diff, min(diff - b % diff, a % diff))
	else:
		print(0, 0)


d = input()
a = [0] * int(d)
b = [0] * int(d)
for i in range(int(d)):
	(a[i], b[i]) = map(int, input().split())
for i in range(0, int(d)):
	m = abs(a[i] - b[i])
	if m == 0:
		print(0, 0)
	elif m == 1:
		print(1, 0)
	elif a[i] % m == 0:
		print(m, 0)
	else:
		print(m, min(m - a[i] % m, a[i] % m))


from math import gcd, ceil
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print('%d %d' % (0, 0))
	else:
		if a > b:
			(a, b) = (b, a)
		ans = b - a
		steps = 0
		r = a % ans
		if r >= ans / 2:
			steps = ceil(a / ans) * ans - a
		else:
			steps = r
		print('%d %d' % (ans, steps))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
		continue
	if a > b:
		(a, b) = (b, a)
	c = b - a
	base1 = a // c
	base2 = base1 + 1
	print(c, min(abs(base1 * c - a), abs(base2 * c - a)))


n = int(input())
l = []
for _ in range(n):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	d = a - b
	if d == 0:
		nb_op = 0
	else:
		nb_op = min(d - a % d, a % d, b)
	l.append(str(d) + ' ' + str(nb_op))
print('\n'.join(l))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	m = abs(a - b)
	if m == 0:
		print(0, 0)
		continue
	small = min(a, b)
	lower = small // m * m
	upper = lower + m
	o = min(small - lower, upper - small)
	print(m, o)


n = int(input())
for m in range(n):
	[a, b] = list(map(int, input().split()))
	if a > b:
		k = a - b
	elif a < b:
		k = b - a
	else:
		print('0 0')
		continue
	if a % k > k / 2:
		x = k - a % k
	else:
		x = a % k
	print(str(k) + ' ' + str(x))


t = int(input())
pairs_of_numbers = []
for i in range(t):
	numbers = input()
	two_numbers = numbers.split(' ')
	pairs_of_numbers.append(two_numbers)
for pair in pairs_of_numbers:
	a = int(pair[0])
	b = int(pair[1])
	max_excitement = abs(a - b)
	if max_excitement == 0:
		print('0 0')
	else:
		modulo_1 = a % max_excitement
		modulo_2 = max_excitement - modulo_1
		min_steps = min(modulo_1, modulo_2)
		print(f'{max_excitement} {min_steps}')


def main():
	test = int(input())
	for _ in range(test):
		(a, b) = map(int, input().split())
		if a == b:
			print('0 0')
			continue
		if a > b:
			(a, b) = (b, a)
		diff = abs(a - b)
		if b % diff == 0:
			print(f'{diff} {0}')
			continue
		mul = a // diff
		s1 = (mul + 1) * diff - a
		s2 = min(a, a - mul * diff)
		print(f'{diff} {min(s1, s2)}')
main()


for s in [*open(0)][1:]:
	(a, b) = map(int, s.split())
	print((d := abs(a - b)), d and min(a % d, -a % d))


def s_a():
	t = int(input())
	arr = []
	for i in range(t):
		(a, b) = tuple([int(x) for x in input().split()])
		(a1, b1) = (a, b)
		d = abs(a - b)
		if d == 0:
			arr.append('0 0')
		elif d == 1:
			arr.append('1 0')
		else:
			i = 0
			m = a % d
			if m <= d // 2:
				i = m
			else:
				i = d - m
			arr.append('{} {}'.format(d, i))
	for el in arr:
		print(el)
s_a()


t = int(input())
while t > 0:
	t -= 1
	(a, b) = map(int, input().split())
	y = abs(a - b)
	if y == 0:
		print(0, 0)
	else:
		z = min(a % y, y - a % y)
		print(y, z)


for s in [*open(0)][1:]:
	(a, b) = map(int, s.split())
	g = abs(a - b)
	if g == 0:
		print(0, 0)
		continue
	print(g, min(a % g, g - a % g))


import math
n = int(input())
for g in range(n):
	(a, b) = map(int, input().split())
	diff = abs(a - b)
	x = min(a, b)
	if a == b:
		print(0, 0)
	else:
		y = x % diff
		z = min(y, diff - y)
		print(diff, z)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	else:
		dif = abs(a - b)
		print(dif, min(a % dif, dif - a % dif))


t = int(input())
i = 0
A = []
while 0 <= i < t:
	i = i + 1
	k = 2
	(a, b) = map(int, input().split())
	c = max(a, b)
	d = min(a, b)
	if c == d:
		A.append('0 0')
	else:
		q = c - d
		if d % q >= q / 2:
			s = q - d % q
		else:
			s = d % q
		A.append(str(q) + ' ' + str(s))
k = -1
while -1 <= k < t - 1:
	k = k + 1
	print(A[k])


from math import cos, pi, ceil, pi, tan, floor, gcd, sqrt, log2, factorial, log10
from collections import Counter
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase
alpha = ascii_lowercase
beta = ascii_uppercase
for ttt in range(int(input())):
	(x, y) = map(int, input().split())
	if x == y:
		print(0, 0)
		continue
	if y - x == 1:
		print(1, 0)
		continue
	if x > y:
		(x, y) = (y, x)
	if x == 0:
		print(y, 0)
		continue
	gg = y - x
	a = ceil(x / gg)
	s = a * gg - x
	print(gg, min(s, x % gg))


t = int(input())
for _ in range(t):
	(m, n) = map(int, input().split())
	if m == n:
		print('0 0')
	else:
		M = abs(m - n)
		step = min(m, n)
		down_step = m % M
		up_step = M - m % M
		print(abs(m - n), min([up_step, down_step, step]))


for tc in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	if a > b:
		(a, b) = (b, a)
	if a == b:
		print(0, 0)
		continue
	diff = b - a
	move = min(a % diff, diff - a % diff)
	print(diff, move)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	else:
		diff = abs(a - b)
		s = min(a % diff, diff - a % diff)
		print(diff, s)


PI = 3.141592653589793
INF = float('inf')
MOD = 1000000007

def bin32(num):
	return '{0:032b}'.format(num)

def add(x, y):
	return (x + y) % MOD

def sub(x, y):
	return (x - y + MOD) % MOD

def mul(x, y):
	return x * y % MOD

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)

def power(x, y):
	res = 1
	x %= MOD
	while y != 0:
		if y & 1:
			res = mul(res, x)
		y >>= 1
		x = mul(x, x)
	return res

def mod_inv(n):
	return power(n, MOD - 2)

def prob(p, q):
	return mul(p, power(q, MOD - 2))

def ii():
	return int(input())

def li():
	return [int(i) for i in input().split()]

def ls():
	return [i for i in input().split()]
for t in range(ii()):
	t += 1
	l = li()
	l.sort()
	a = l[0]
	b = l[1]
	if a == b:
		print(0, 0)
		continue
	diff = b - a
	re = a % diff
	print(diff, min(diff - re, re))


import sys, math
input = sys.stdin.readline
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	a = min(x, y)
	b = max(x, y)
	if b == a:
		print(0, 0)
	else:
		print(b - a, min(b - a - a % (b - a), a % (b - a)))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	x = abs(n - m)
	if x == 0:
		print(0, 0)
	else:
		y = n % x
		y = min(y, x - y)
		z = m % x
		z = min(z, x - z)
		print(x, min(y, z))


def main():
	(A, B) = map(int, input().split())
	if A == B:
		return print(0, 0)
	C = abs(A - B)
	A %= C
	print(C, min(A, C - A))
T = int(input())
for _ in range(T):
	main()


import math
for i in range(int(input())):
	(f, g) = map(int, input().split())
	a = max(f, g)
	b = min(f, g)
	if math.gcd(a, b) == abs(a - b):
		print(abs(a - b), 0)
		continue
	if a == b:
		print(0, 0)
		continue
	if b == 0:
		print(a - b, 0)
		continue
	l = a - b
	m = a // l
	p = m * l
	u = (m + 1) * l
	if a - p < u - a:
		print(a - b, a - p)
	else:
		print(a - b, u - a)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	answer = 0
	(a, b) = map(int, input().split())
	if a < b:
		(a, b) = (b, a)
	diff = a - b
	if diff == 0:
		answer = 0
	else:
		answer = min(b, a % diff)
		answer = min(answer, diff - a % diff)
	print(diff, answer)


import math

def main():
	t = int(input())
	for _ in range(t):
		print(case())

def case():
	(a, b) = sorted(list(map(int, input().split())))
	d = b - a
	if d == 0:
		return '0 0'
	if d == 1:
		return '1 0'
	return f'{d} {min(a % d, d - a % d)}'
main()


import math
import sys
input = sys.stdin.readline

def chk(p, a):
	if p % a == 0:
		return 0
	return 1
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		sys.stdout.write(str(0) + ' ' + str(0) + '\n')
		continue
	ans = max(a, b) - min(a, b)
	num1 = 0
	num2 = ans
	e1 = min(a, b) - min(a, b) // ans * ans
	e2 = (min(a, b) // ans + chk(min(a, b), ans)) * ans - min(a, b)
	sys.stdout.write(str(ans) + ' ' + str(min(e1, e2, ans)) + '\n')


import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
	return sys.stdin.readline()[:-1]
T0 = int(input())
for _ in range(T0):
	(A, B) = map(int, input().split())
	if A > B:
		(A, B) = (B, A)
	if A == B:
		print(0, 0)
	else:
		d = B - A
		print(d, min(A % d, d - A % d))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	else:
		g = abs(a - b)
		steps = min(a % g, g - a % g)
		print(g, steps)


from math import *
t = int(input())
while t != 0:
	t -= 1
	tmp = input().split()
	a = max(int(tmp[0]), int(tmp[1]))
	b = min(int(tmp[0]), int(tmp[1]))
	if a == b:
		print(0, 0)
		continue
	x = a - b
	y = b - int(b / x) * x
	w = int(b / x + 1) * x - b
	print(x, min(y, w))


t = int(input())
for i in range(t):
	(r, s) = map(int, input().split())
	if r == s:
		print(0, 0)
	else:
		a = min(r, s)
		b = max(r, s)
		q = b - a
		n = b % q
		print(q, min(n, q - n))


w = int(input())
flag = 0
l = []
for i in range(w):
	t = list(map(int, input().split()))
	l.append(t)
for i in l:
	i.sort()
	gcd = i[1] - i[0]
	if gcd == 0:
		print('0 0')
	else:
		ans = min(i[0] % gcd, i[1] % gcd, abs(i[0] % gcd - gcd), abs(i[1] % gcd - gcd))
		print(gcd, ans)


import sys, os
import math
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
from io import BytesIO, IOBase

def getNum(x):
	num = x
	count = -1
	a = []
	while x > 0:
		a.append(x % 10)
		count += 1
		x //= 10
	y = num * 10 ** count
	z = 0
	k = 0
	for i in range(len(a) - 1, 0, -1):
		z += a[i] * 10 ** k
		k += 1
	return y + z

def main():
	for _ in range(mi()):
		(a, b) = MI()
		if a == b:
			print(0, 0)
			continue
		cx0 = abs(b - a)
		ch0 = a % cx0
		ch1 = cx0 - ch0
		print(cx0, min(ch0, ch1))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def MI():
	return map(int, input().split())

def mi():
	return int(input())

def outP(var):
	sys.stdout.write(str(var) + '\n')
MOD = 10 ** 9 + 7
mod = 998244353
main()


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		e = 0
		m = 0
		print(e, m, sep=' ')
	else:
		e = abs(a - b)
		if a % e >= e / 2:
			m = abs(e - a % e)
		elif a % e < e / 2:
			m = abs(a % e)
		m = min(m, b)
		print(e, m, sep=' ')


from math import gcd
n = int(input())
pairs = [None] * n
gcds = [0] * n
steps = [0] * n
for i in range(n):
	pairs[i] = list(map(int, input().split()))
for i in range(n):
	a = min(pairs[i][0], pairs[i][1])
	b = max(pairs[i][0], pairs[i][1])
	if not a == b:
		g = b - a
		gcds[i] = g
		steps[i] = min(a % g, g - a % g)
	print(gcds[i], steps[i])


import math
n = int(input())
results = []
for i in range(n):
	cur_input = [int(j) for j in input().split(' ')]
	a = max(cur_input[0], cur_input[1])
	b = cur_input[0] + cur_input[1] - a
	if a == b:
		results.append([0, 0])
		continue
	if b == 0:
		results.append([a, 0])
		continue
	diff = a - b
	if b >= diff:
		if b % diff > diff / 2:
			results.append([diff, diff - b % diff])
		else:
			results.append([diff, b % diff])
	elif b == 1:
		results.append([diff, 1])
	else:
		results.append([diff, min(b, diff - b)])
for arr in results:
	print(f'{arr[0]} {arr[1]}')


t = int(input())
for i in range(t):
	(a, b) = map(int, input().strip().split())
	if a == b:
		print(0, 0)
	elif abs(a - b) == 1:
		print(1, 0)
	else:
		gcd = abs(a - b)
		minimum = min(a, b)
		temp = minimum // gcd
		prv = minimum - temp * gcd
		nxt = (temp + 1) * gcd - minimum
		print(gcd, min(nxt, prv))


t = int(input())
ans = []
for i in range(t):
	(a, b) = tuple(map(int, input().split()))
	maks = max(a, b)
	diff = abs(a - b)
	moves = 0
	if diff == 0:
		moves = diff
	elif maks % diff > (maks // diff + 1) * diff - maks:
		moves = (maks // diff + 1) * diff - maks
	else:
		moves = maks % diff
	ans.append([str(diff), str(moves)])
for case in tuple(ans):
	print(' '.join(case).strip())


import math
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	(a, b) = (max(a, b), min(a, b))
	if a == b:
		print('0 0')
	elif b == 0:
		print(a, '0')
	elif b <= a / 2:
		print(a - b, min(b, a - b * 2))
	elif a % (a - b) == 0:
		print(a - b, 0)
	else:
		print(a - b, min(b % (a - b), a - b - b % (a - b)))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	else:
		diff = abs(a - b)
		if a % diff:
			if a % diff > diff / 2:
				print(diff, diff - a % diff)
			else:
				print(diff, a % diff)
		else:
			print(diff, 0)


def main():
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		gcd = abs(a - b)
		if gcd == 0:
			print('0 0')
		else:
			print(gcd, min(a % gcd, gcd - a % gcd))
main()


import os, sys, math
from io import BytesIO, IOBase
from collections import defaultdict, deque, OrderedDict
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(input())

def In():
	return map(int, input().split())

def ln():
	return list(map(int, input().split()))

def Sn():
	return input().strip()
BUFSIZE = 8192

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return len(a)

def solve():
	(a, b) = In()
	if a > b:
		(a, b) = (b, a)
	t = b - a
	if t == 0:
		print(0, 0)
		return
	(mn, mx) = (a - a % t, a + (t - a % t))
	print(t, min(mx - a, a - mn))
	pass

def main():
	T = I()
	for i in range(T):
		solve()
M = 998244353
P = 1000000007

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def process(x, y):
	if x > y:
		(m, c) = (y, x - y)
	else:
		(m, c) = (x, y - x)
	if c == 0:
		return (0, 0)
	elif m % c == 0:
		return (c, 0)
	else:
		t = int(m / c)
		return (c, min(m - t * c, (t + 1) * c - m))
n = int(input())
input_list = list()
for _ in range(n):
	s = input().strip().split()
	input_list.append((int(s[0]), int(s[1])))
for (x, y) in input_list:
	(a, b) = process(x, y)
	print('%s %s' % (a, b))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
		continue
	(a, b) = (max(a, b), min(a, b))
	ans = a - b
	if a % ans == 0:
		c = 0
	else:
		c = min(a - ans * (a // ans), ans * (a // ans + 1) - a)
	print(ans, c)


import sys, os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(a, b):
	if a % b == 0:
		return b
	return gcd(b, a % b)
for t in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(0, 0)
	else:
		v1 = max(a, b)
		v2 = min(a, b)
		val = v1 - v2
		p1 = v1 % val
		value = min(p1, val - p1)
		print(val, value)


def solve(a, b):
	d = abs(a - b)
	if not d:
		print(0, 0)
		return
	print(d, min(a % d, d - a % d))
(t,) = map(int, input().split())
for _ in range(t):
	(a, b) = map(int, input().split())
	solve(a, b)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	else:
		mx = abs(a - b)
		mn = min(a % mx, (mx - a) % mx)
		print(mx, mn)


import sys
import math
from collections import deque
from bisect import bisect_left, bisect_right
I = sys.stdin.readline
II = lambda : int(I())
IN = lambda x: map(int, x.split())
L = lambda x: list(IN(x))
M = 1000000007
P = print
T = True
F = False
for _ in range(II()):
	(a, b) = IN(I())
	if a == b:
		print(0, 0)
		continue
	if b > a:
		(a, b) = (b, a)
	g = a - b
	q = b // g
	n = min(b - q * g, (q + 1) * g - b)
	P(g, n)


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(0, 0)
	else:
		max_exi = abs(a - b)
		min_mov = min(a, b) // max_exi
		c = abs(min_mov * max_exi - min(a, b))
		d = abs((min_mov + 1) * max_exi - min(a, b))
		print(max_exi, min(c, d))


aa = int(input())
for i in range(aa):
	temp = 0
	(x, y) = map(int, input().split())
	if x < y:
		temp = x
		x = y
		y = temp
	if x == y:
		print('0 0')
		continue
	else:
		g_c_d = abs(x - y)
		z = x % g_c_d
		mini = min(z, g_c_d - z)
	print(g_c_d, mini)


def getlistint():
	return list(map(int, stdin.readline().split()))

def getmapint():
	return map(int, stdin.readline().split())

def getliststr():
	return list(stdin.readline().split())

def getint():
	return int(stdin.readline().strip())

def getstr():
	return stdin.readline().strip()

def pr(s):
	stdout.write(str(s) + '\n')

def prlist(l):
	stdout.write(' '.join(list(map(str, l))) + '\n')
from sys import stdin, stdout
from math import gcd
for _ in range(getint()):
	(a, b) = getmapint()
	(a, b) = (min(a, b), max(a, b))
	m = b - a
	if gcd(a, b) != m and gcd(a, b) != b:
		k = b // m * m
		steps = min(b - k, k + m - b)
		pr(str(m) + ' ' + str(steps))
	else:
		pr(str(m) + ' 0')


t = int(input(''))
import math
(i, it, a, b) = (0, 0, t * [0], t * [0])
while i < t:
	(a[i], b[i]) = map(int, input().split())
	i += 1
for i in range(0, t):
	diff = abs(a[i] - b[i])
	if diff != 0:
		lol = a[i] % diff
		if lol < diff / 2:
			print(diff, lol)
		else:
			print(diff, diff - lol)
	else:
		print(0, 0)


t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	if a < b:
		temp = a
		a = b
		b = temp
	diff = a - b
	if diff == 0:
		print('0 0')
	elif diff == 1:
		print('1 0')
	else:
		low = a // diff
		if a - low * diff > 0.5 * diff:
			low = low + 1
		c = low * diff
		d = (low - 1) * diff
		steps = abs(c - a)
		print(diff, steps)


t = int(input())
while t:
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if a == b:
		print(0, 0)
	elif a < b:
		(a, b) = (b, a)
		c = a - b
		print(a - b)
		print(min(c - a % c, a % c))
		print('\n')
	else:
		c = a - b
		print(a - b)
		print(min(c - a % c, a % c))
		print('\n')
	t -= 1


from collections import deque
import heapq
from math import sqrt
import operator
from operator import itemgetter
import sys
import copy
inf_var = 0
if inf_var == 1:
	inf = open('input.txt', 'r')
else:
	inf = sys.stdin
input = inf.readline

def read_one_int():
	return int(input().rstrip('\n'))

def read_one_float():
	return float(input().rstrip('\n'))

def read_list_of_ints():
	res = [int(val) for val in input().rstrip('\n').split(' ')]
	return res

def read_str():
	return input().rstrip()

def main():
	tests = read_one_int()
	for _ in range(tests):
		(a, b) = read_list_of_ints()
		if a < b:
			(a, b) = (b, a)
		gcd = a - b
		if gcd == 0:
			print('{} {}'.format(0, 0))
			continue
		oper_cnt_1 = a % gcd
		oper_cnt_2 = None
		if oper_cnt_1 != 0:
			oper_cnt_2 = gcd - oper_cnt_1
		if oper_cnt_2 is not None:
			oper_cnt = min(oper_cnt_2, oper_cnt_1)
		else:
			oper_cnt = oper_cnt_1
		print('{} {}'.format(gcd, oper_cnt))
main()


t = int(input())
for i in range(t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	ans = abs(a - b)
	ans2 = 0
	if ans != 0:
		ans2 = a % ans
		if ans2 > ans - ans2:
			ans2 = ans - ans2
	print(str(ans) + ' ' + str(ans2))


def il():
	return list(map(int, input().split()))

def ii():
	return int(input())

def imi():
	return map(int, input().split())
from math import *
t = ii()
for _ in range(t):
	(a, b) = imi()
	if a == b:
		print(0, 0)
	else:
		k = abs(b - a)
		a = min(a, b)
		x = min(a - a // k * k, ceil(a / k) * k - a)
		print(k, x)


t = int(input())
for p in range(t):
	l = list(map(int, input().rstrip().split()))
	a = l[0]
	b = l[1]
	if a == b:
		print(f'0 0')
	else:
		print(abs(a - b), end=' ')
		if abs(a - b) == 1:
			print(0)
		else:
			print(min(abs(a - b) - a % abs(a - b), a % abs(a - b)))


for i in [*open(0)][1:]:
	(a, b) = map(int, i.split())
	if a == b:
		print(0, 0)
	else:
		g = e = abs(a - b)
		c = min(a, b)
		while g < c:
			g += e
		if g - c < abs(g - e - c):
			d = g - c
		else:
			d = abs(g - e - c)
		print(e, d)


trails = int(input())
answer_list = []
for x in range(trails):
	numbers = input().split(' ')
	n = int(numbers[0])
	k = int(numbers[1])
	if n == k:
		tup = (0, 0)
		answer_list.append(tup)
		continue
	answer_ex = abs(k - n)
	mod = n % answer_ex
	if mod > answer_ex / 2:
		ans_st = answer_ex - mod
	else:
		ans_st = mod
	answer = (answer_ex, ans_st)
	answer_list.append(answer)
for g in answer_list:
	print(g[0], end=' ')
	print(g[1])


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
		continue
	if abs(a - b) == 1:
		print(1, 0)
		continue
	c = abs(a - b)
	d = a // c
	e = d + 1
	if a - c * d <= c * e - a:
		print(c, a - c * d)
	else:
		print(c, c * e - a)


import math
import os
import sys
from sys import *
from decimal import *
from io import BytesIO, IOBase
from itertools import accumulate, combinations, permutations, combinations_with_replacement, product
from collections import *
M = 10 ** 9 + 7
import heapq
from bisect import *
from functools import lru_cache
from queue import PriorityQueue
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())

def luckynumber(x, n, a):
	if x > 0:
		a.append(x)
	if x > 10 ** 9:
		return a
	elif x < 1000000000000.0:
		luckynumber(x * 10 + 4, n, a)
		luckynumber(x * 10 + 7, n, a)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def query1(l, r):
	if l >= r:
		return -1
	print('?', l + 1, r + 1)
	sys.stdout.flush()
	return int(input()) - 1

def answer(p):
	print('!', p + 1)
	sys.stdout.flush()
	exit()

def rse(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(n)
		else:
			while len(stack) != 0:
				if stack[-1][0] >= arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(n)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def lse(arr, n):
	stack = []
	ans = []
	for i in range(n):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) != 0:
				if stack[-1][0] >= arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	return ans

def mah(arr):
	max1 = 0
	p = rse(arr, len(arr))
	q = lse(arr, len(arr))
	for i in range(len(arr)):
		a = (p[i] - q[i] - 1) * arr[i]
		max1 = max(a, max1)
	return max1

class Graph(object):

	def __init__(self, vertices):
		self.graph = defaultdict(list)
		self.V = vertices

	def addEdge(self, u, v):
		self.graph[u].append(v)
		self.graph[v].append(u)

	def connectedComponents(self):
		unvisited = set(range(self.V))
		queue = deque()
		count = 0
		while len(unvisited) > 0:
			count += 1
			v = next(iter(unvisited))
			unvisited.remove(v)
			queue.append(v)
			while len(queue) > 0:
				v = queue.popleft()
				for w in self.graph[v]:
					if w in unvisited:
						unvisited.remove(w)
						queue.append(w)
		return count

def maxSumIS(arr, n):
	msis = arr.copy()
	for i in range(1, n):
		for j in range(i):
			if arr[i] > arr[j] and msis[i] < msis[j] + arr[i]:
				msis[i] = msis[j] + arr[i]
	c = max(msis)
	p = 5
	return c

def binarysearch2(arr, target):
	lo = 0
	hi = len(arr) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if arr[mid] == target:
			if mid != len(arr) - 1:
				if arr[mid + 1] != target:
					return mid
				else:
					lo += 1
			else:
				return mid
			continue
		if arr[mid] > target:
			hi = mid - 1
		else:
			lo = mid + 1

def ngr(arr, n):
	stack = []
	ans = []
	for i in range(n - 1, -1, -1):
		if len(stack) == 0:
			ans.append(-1)
		else:
			while len(stack) > 0:
				if stack[-1][0] < arr[i]:
					stack.pop()
				else:
					break
			if len(stack) == 0:
				ans.append(-1)
			else:
				ans.append(stack[-1][1])
		stack.append([arr[i], i])
	ans.reverse()
	return ans

def alperm(nums, path, result):
	if not nums:
		result.add(tuple(path))
		return
	for i in range(0, len(nums)):
		alperm(nums[:i] + nums[i + 1:], path + [nums[i]], result)
	return result

def minsum(arr, n, m, res, l):
	if n == 1 and m == 1:
		res += arr[0][0]
		l.append(res)
	else:
		if n != 1:
			p = res + arr[n - 1][m - 1]
			minsum(arr, n - 1, m, p, l)
		if m != 1:
			p = res + arr[n - 1][m - 1]
			minsum(arr, n, m - 1, p, l)
	return min(l)

def subset(arr, n, ans, c):
	if n == 0:
		print(c)
		ans.add(tuple(sorted(c)))
		return
	else:
		op = c + [arr[n - 1]]
		subset(arr, n - 1, ans, op)
		subset(arr, n - 1, ans, c)

def catalan(n):
	if n == 0 or n == 1:
		return 1
	catalan = [0] * (n + 1)
	catalan[0] = 1
	catalan[1] = 1
	for i in range(2, n + 1):
		for j in range(i):
			catalan[i] += catalan[j] * catalan[i - j - 1]
	return catalan[n]

def isP(p, i, j):
	if j <= i:
		return True
	if p[i] != p[j]:
		return False
	return isP(p, i + 1, j - 1)

def main():
	t = 1
	t = inpu()
	for _ in range(t):
		(a, b) = sep()
		q = 0
		p = abs(a - b)
		if p == 0:
			print(0, 0)
			continue
		c = min(a, b)
		d = max(a, b)
		s = c // p
		ans = min((s + 1) * p - c, c - s * p)
		print(p, ans)
main()


from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import gcd
setrecursionlimit(10 ** 7)
for _ in range(int(stdin.readline())):
	(a, b) = map(int, stdin.readline().split())
	if a == b:
		print(0, 0)
		continue
	if a < b:
		(a, b) = (b, a)
	temp_ans = a - b
	if gcd(a, b) == temp_ans:
		ans = (temp_ans, 0)
	else:
		temp = b % temp_ans
		ans = (temp_ans, min(b, temp_ans - temp, temp))
	print(ans[0], ans[1])


from sys import stdin as sin

def aint():
	return int(input())

def amap():
	return map(int, sin.readline().split())

def alist():
	return list(map(int, sin.readline().split()))

def astr():
	return input()
from math import gcd, ceil, floor
for _ in range(aint()):
	(a, b) = amap()
	k = abs(a - b)
	if k == 0:
		print(0, 0)
	elif a < b:
		x = abs(k - a)
		w = abs(b - int(floor(b / k) * k))
		z = abs(b - int(ceil(b / k) * k))
		print(k, min(x, w, z))
	else:
		x = abs(k - b)
		w = abs(a - int(floor(a / k) * k))
		z = abs(a - int(ceil(a / k) * k))
		print(k, min(x, w, z))


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	c = 0
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(0, 0)
	else:
		g = abs(a - b)
		print(g, min(a % g, g - a % g))


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
for t in range(int(input())):
	(a, b) = map(int, input().split())
	maxi = abs(a - b)
	gd = gcd(a, b)
	if a == b:
		print(0, 0)
	else:
		diff = abs(a - b)
		a = min(a, b)
		moves = min(a % diff, diff - a % diff)
		print(maxi, moves)


T = int(input())
for _ in range(T):
	(a, b) = map(int, input().split(' '))
	if a < b:
		(a, b) = (b, a)
	if a == b:
		print('0 0')
	else:
		d = a - b
		steps = min(b % d, d - b % d)
		print('{} {}'.format(d, steps))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	excitement = abs(a - b)
	if excitement != 0:
		moves = min(a % excitement, excitement - a % excitement)
	else:
		moves = 0
	print(excitement, moves)


def excitement(a, b):
	if a == b:
		return [0, 0]
	gcd = max(a, b) - min(a, b)
	moves = max(a, b) % gcd
	if moves > gcd // 2:
		moves = gcd - moves
	return [gcd, moves]
ans = []
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	ans.append(excitement(a, b))
for i in ans:
	i = list(map(str, i))
	print(' '.join(i))


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	(c, d) = (max(a, b), min(a, b))
	diff = c - d
	if diff == 0:
		print(0, 0)
	elif d % diff == 0:
		print(diff, 0)
	else:
		m = d // diff
		ans = min(d - m * diff, (m + 1) * diff - d)
		print(diff, ans)


for data_samples in range(int(input())):
	arr = list(map(int, input().split()))
	if arr[0] == arr[1]:
		print('0 0')
	else:
		max_azart = abs(arr[0] - arr[1])
		closest_nums = [min(arr) // max_azart * max_azart, (min(arr) // max_azart + 1) * max_azart]
		minimum_moves = min(abs(min(arr) - closest_nums[0]), abs(min(arr) - closest_nums[1]))
		print(max_azart, minimum_moves)


import os, sys, math
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil
mod = 10 ** 9 + 7
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	elif a == b - 1 or b == a - 1:
		print(1, 0)
	else:
		aa = a
		bb = b
		if aa < bb:
			bb = bb - aa
			aa = 0
		else:
			aa = aa - bb
			bb = 0
		first_num = aa
		second_num = bb
		if first_num == 0:
			intial_gcd = second_num
		else:
			intial_gcd = first_num
		if a % intial_gcd == 0 and b % intial_gcd == 0:
			print(intial_gcd, 0)
		else:
			s = 0
			e = pow(10, 18)
			till = 0
			while s <= e:
				m = s + (e - s) // 2
				if intial_gcd * m >= a:
					e = m - 1
					till = intial_gcd * m
				else:
					s = m + 1
			m1 = abs(till - a)
			s = 0
			e = pow(10, 18)
			till = 0
			while s <= e:
				m = s + (e - s) // 2
				if m * intial_gcd <= a:
					s = m + 1
					till = intial_gcd * m
				else:
					e = m - 1
			print(intial_gcd, min(abs(till - a), m1))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter, defaultdict
import math
import heapq
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	e = abs(a - b)
	if a == b:
		print(0, 0)
	elif a >= e and b >= e:
		if a % e == 0 and b % e == 0:
			print(e, 0)
		else:
			x = a // e
			y1 = e * x
			l = abs(a - y1)
			y = b / e
			x += 1
			x1 = e * x
			d = abs(x1 - a)
			c1 = min(a, b)
			d = min(d, c1)
			d = min(l, d)
			print(e, d)
	else:
		x = a // e
		y1 = e * x
		l = abs(a - y1)
		y = b // e
		x += 1
		x1 = e * x
		d = abs(x1 - a)
		c1 = min(a, b)
		d = min(d, c1)
		d = min(l, d)
		print(e, d)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(str(0) + ' ' + str(0))
	else:
		g = abs(a - b)
		moves = min(a % g, g - a % g)
		print(str(g) + ' ' + str(moves))


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import math
t = int(input())
while t > 0:
	t -= 1
	(a, b) = sorted(list(map(int, input().split())))
	if a == 0:
		print(str(b) + ' 0')
		continue
	if a == b:
		print('0 0')
		continue
	if b - a == 1:
		print('1 0')
		continue
	else:
		g = b - a
		print(str(g) + ' ' + str(min(b % g, g - b % g)))


t = int(input())
for i in range(t):
	[a, b] = input().split()
	a = int(a)
	b = int(b)
	c = max(a, b)
	d = min(a, b)
	if c == d:
		print('0 0')
	else:
		temp1 = c - d
		temp2 = min(c % (c - d), c - d - c % (c - d))
		print(f'{temp1} {temp2}')


def main():
	alpha = 'abcdefghijklmnopqrstuvwxyz'
	ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	inf = 1e+17
	mod = 10 ** 9 + 7

	def factorial(n):
		f = 1
		for i in range(1, n + 1):
			f = f * i % mod
		return f

	def ncr(n, r):
		num = den = 1
		for i in range(r):
			num = num * (n - i) % mod
			den = den * (i + 1) % mod
		return num * pow(den, mod - 2, mod) % mod

	def solve(a, b):
		if a == b:
			print(0, 0)
			return
		GCD = max(a, b) - min(a, b)
		print(GCD, min(min(a, b) % GCD, GCD - min(a, b) % GCD))
		pass
	t = int(input())
	ans = []
	for _ in range(t):
		(a, b) = map(int, input().split())
		ans.append(solve(a, b))
import sys, threading
import bisect
import math
import itertools
from sys import stdout
import heapq
from queue import PriorityQueue
input = sys.stdin.readline
thread = threading.Thread(target=main)
thread.start()
thread.join()


def excitement(a, b):
	ans = abs(a - b)
	diff1 = diff2 = 0
	if ans == 0:
		return (0, 0)
	if a % ans != 0:
		diff1 = min(ans - a % ans, a % ans)
	if b % ans != 0:
		diff2 = min(ans - b % ans, b % ans)
	diff = min(diff1, diff2)
	return (ans, diff)
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	(max_gcd, diff) = excitement(a, b)
	print(max_gcd, diff)


import sys
import math

def solve():
	(a, b) = map(int, input().split())
	if a == b:
		print('0 0')
	else:
		r = abs(a - b)
		z = max(a, b)
		if math.gcd(a, b) == r:
			print(r, '0')
		else:
			z = max(a, b)
			e = z // r
			y1 = (e + 1) * r - z
			y2 = abs(e * r - z)
			print(abs(a - b), min(y1, y2))
t = int(input())
while t != 0:
	solve()
	t -= 1


from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	else:
		print(abs(a - b), min(a % abs(a - b), max(a, b) - b % abs(b - a) + abs(b - a) - max(a, b)))


from math import gcd
t = int(input())
for i in range(0, t):
	(a, b) = map(int, input().split())
	maxim = max(a, b)
	minim = min(a, b)
	a = maxim
	b = minim
	if a - b == 1 or b - a == 1:
		print('1 0')
	elif a == b:
		print('0 0')
	else:
		x = a - b
		q = b // x
		moves = min(b % x, (q + 1) * x - b)
		print(str(x) + ' ' + str(moves))


def cf_730A(a: int, b: int):
	diff = abs(b - a)
	if not diff:
		return (diff, diff)
	else:
		return (diff, min(a - a // diff * diff, (a // diff + 1) * diff - a))
for _ in range(int(input())):
	print(*cf_730A(*map(int, input().split())))


import sys
import math
import collections
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, end=' ')
		print(0)
	else:
		diff = max(a, b) - min(a, b)
		if b > a:
			(a, b) = (b, a)
		maxvalue = diff
		maxmoves = min(b % diff, diff - b % diff)
		print(diff, end=' ')
		print(maxmoves)


t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	g = abs(a - b)
	if g == 0:
		print('0 0')
	else:
		lb = a // g
		hb = lb + 1
		if a - lb * g < hb * g - a:
			mo = a - lb * g
		else:
			mo = hb * g - a
		print(g, mo)


from sys import stdin
input = stdin.readline
rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().strip()
YN = lambda x: print('YES') if x else print('NO')
mod = 10 ** 9 + 7
for _ in range(rn()):
	(a, b) = rns()
	c = abs(a - b)
	if c == 0:
		print(0, 0)
	else:
		print(c, min((c - a % c) % c, a % c))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	temp = abs(a - b)
	if temp == 0:
		print(0, 0)
		continue
	temp2 = min(a % temp, b % temp, abs(temp - a % temp), abs(temp - b % temp))
	print(temp, temp2)


import os
import sys
import math
import collections
import functools
import itertools
import heapq
import bisect
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcde'
MOD = 10 ** 9 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def INT():
	return int(input())

def STR():
	return input()

def INTs():
	return tuple(map(int, input().split()))

def ARRINT():
	return [int(i) for i in input().split()]

def ARRSTR():
	return [i for i in input().split()]
for _ in range(INT()):
	(a, b) = INTs()
	if a == b:
		print('0 0')
	else:
		diff = abs(a - b)
		step = min(a % diff, diff - a % diff)
		print(str(diff) + ' ' + str(step))


import sys, os
from io import BytesIO, IOBase
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def ceil(a, b):
	return (a + b - 1) // b

def lcm(a, b):
	return a * b // gcd(a, b)
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
from math import gcd

def solve():
	(a, b) = lmp()
	excitement = abs(a - b)
	if excitement == 0:
		print('0 0')
	else:
		print(f'{excitement} {min(a % excitement, excitement - a % excitement)}')
t = iinp()
while t:
	solve()
	t -= 1


import math

def _1543a(a, b):
	if a != b:
		d = abs(a - b)
		c = min(a, b)
		i = 0
		while i * d < c:
			i += 1
		if i * d - c > c - (i - 1) * d:
			noo = c - (i - 1) * d
		else:
			noo = i * d - c
		return str(d) + ' ' + str(noo)
	else:
		return '0 0'
t = int(input())
inpt = []
answers = []
for i in range(t):
	inp = input()
	inpt.append(inp)
for i in inpt:
	a = int(i.split()[0])
	b = int(i.split()[1])
	answers.append(_1543a(a, b))
for i in answers:
	print(i)


for _ in range(int(input())):
	(a, b) = [int(__) for __ in input().split()]
	if a == b:
		print(0, 0)
		continue
	shit = abs(a - b)
	x = min(a, b)
	print(shit, min(x % shit, shit - x % shit))


import math
import sys
from functools import reduce
import decimal
sys.setrecursionlimit(10 ** 9)
decimal.getcontext().rounding = decimal.ROUND_HALF_UP

def rounding(n):
	return int(decimal.Decimal(f'{n}').to_integral_value())

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def inp():
	return sys.stdin.readline().strip()

def map_inp(v_type):
	return map(v_type, inp().split())

def list_inp(v_type):
	return list(map_inp(v_type))
for _ in range(int(inp())):
	(a, b) = map_inp(int)
	diff = abs(a - b)
	if diff < 2:
		print(diff, 0)
	else:
		temp1 = a // diff
		temp2 = min(abs(a - diff * temp1), abs(a - diff * (temp1 + 1)))
		print(diff, temp2)


import math
d = int(input())
for p in range(0, d):
	m = 0
	n = 0
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(0, 0)
		continue
	x = math.gcd(a, b)
	if a > b:
		l = a - b
	else:
		l = b - a
	if x == l:
		print(x, 0)
		continue
	q = a % l
	w = l - q
	print(l, min(q, w))


t = int(input())
for i in range(t):
	(a, b) = [int(k) for k in input().split()]
	if b == a:
		print(0, 0)
	else:
		x = abs(b - a)
		(a, b) = sorted([a, b])
		print(x, min(a % x, x - a % x))


from math import *
t = int(input())
for i in range(t):
	temp = input().split()
	x = int(temp[0])
	y = int(temp[1])
	gre = abs(x - y)
	if gre != 0:
		num = min(x % gre, y % gre, gre - x % gre, gre - x % gre)
	else:
		num = 0
	print(str(gre) + ' ' + str(num))


kol = int(input())
for i in range(kol):
	(a, b) = [int(i) for i in input().split()]
	if a == b:
		print(0, 0)
	else:
		g = abs(a - b)
		m = min(a % g, g - a % g)
		print(g, m)


import random
import math
import sys
parse_input = lambda : sys.stdin.readline().rstrip('\r\n')

def func(a, b):
	if a == b:
		return (0, 0)
	if abs(a - b) == 1:
		return (1, 0)
	if a > 0 and b > 0:
		e = abs(a - b)
		gcd = math.gcd(a, b)
		if e == gcd:
			return (e, 0)
		else:
			max_e = max(gcd, e)
		moves = min(min(a, b) % max_e, max_e - min(a, b) % max_e)
		return (max_e, moves)
	elif a == 0 or b == 0:
		return (max(a, b), 0)

def main():
	n_cases = int(parse_input())
	for i in range(n_cases):
		(a, b) = [int(i) for i in parse_input().split()]
		(max_e, moves) = func(a, b)
		print('{} {}'.format(max_e, moves))
main()


from math import gcd
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == b:
		print(0, 0)
	elif abs(a - b) == 1:
		print(1, 0)
	else:
		print(abs(a - b), min(a % abs(a - b), abs(a - b) - a % abs(a - b)))


t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	if a == b:
		print(0, 0)
	else:
		(a, b) = (max(a, b), min(a, b))
		if a % (a - b) == 0:
			print(a - b, 0)
		else:
			res = min(a % (a - b), a - b - a % (a - b))
			print(a - b, res)


from sys import stdin, stdout

def arrin():
	return list(map(int, stdin.readline().split()))

def num1in():
	return int(stdin.readline())

def num2in():
	(a, b) = map(int, stdin.readline().split())
	return (a, b)

def num3in():
	(a, b, c) = map(int, stdin.readline().split())
	return (a, b, c)

def num4in():
	(a, b, c, d) = map(int, stdin.readline().split())
	return (a, b, c, d)

def num5in():
	(a, b, c, d, e) = map(int, stdin.readline().split())
	return (a, b, c, d, e)
t = num1in()
for test in range(t):
	(a, b) = num2in()
	diff = abs(a - b)
	if diff == 0:
		print(0, 0)
		continue
	n1 = a // diff
	n2 = n1 + 1
	n1 = n1 * diff
	n2 = n2 * diff
	moves = min(abs(a - n1), abs(a - n2))
	print(diff, moves)


a = int(input())
for i in range(0, a):
	(b, c) = [int(x) for x in input().split()]
	if b == c:
		print(0, 0)
	elif b == 0 or c == 0:
		print(max(b, c), 0)
	else:
		d = abs(b - c)
		count = min(c % d, d - c % d)
		print(d, count)


import sys
input = iter(sys.stdin.read().splitlines()).__next__

def solve(a, b):
	d = abs(a - b)
	if d == 0:
		return (0, 0)
	m = min(a - a // d * d, (a + d - 1) // d * d - a)
	return (d, m)
TC = int(input())
for tc in range(TC):
	(a, b) = map(int, input().split())
	res = solve(a, b)
	print('%d %d' % res)


t = int(input())
while t > 0:
	t = t - 1
	(a, b) = map(int, input().split())
	if a == b:
		print('0 0')
	elif a < b:
		temp = int(b - a)
		ans = min(a % temp, temp - a % temp)
		print(temp, ans)
	else:
		temp = int(a - b)
		ans = min(b % temp, temp - b % temp)
		print(temp, ans)


import math, sys

def solve():
	(n, m) = map(int, input().split())
	if n == m:
		print('0 0')
	else:
		diff = abs(n - m)
		if n % diff == 0:
			ans = 0
		else:
			f = n // diff
			diff1 = n - f * diff
			diff2 = (f + 1) * diff - n
			ans = min(diff1, diff2)
		print(diff, ans)
t = int(input())
while t != 0:
	solve()
	t -= 1