# 求a, b最大公约数,同时求出裴蜀定理中的一组系数x, y, 满足x*a + y*b = gcd(a, b)
def exp_gcd(a, b):
flag = True
if a > b:
flag = False
a, b = b, a
if a == 0:
return (b, 0, 1) if flag else (b, 1, 0)
gcd_val, x, y = exp_gcd(b%a, a)
new_x = y - x * (b // a)
new_y = x
return (gcd_val, new_x, new_y) if flag else (gcd_val, new_y, new_x)
n = int(input())
for _ in range(n):
a, b = map(int, input().split())
ans = exp_gcd(a, b)
print(ans[1], ans[2])