import sys rr = sys.stdin Q = int(rr.readline()) def gcd(a,b): #if b == 0:return a while True: r = a % b a = b b = r if r == 0:return a def calc(p,q,l): d = q - p if d == 1: return 10 ** 10 tmp = 10 ** 10 for k in l: if k > d:break if d % k == 0: u = k - p % k if u < tmp:tmp = u return tmp def div(d): l = set() i = 1 while i * i <= d: if d % i == 0: if i > 1: l.add(i) l.add(d // i) i += 1 return sorted(l) for _ in range(Q): p,q,r,s = map(int,rr.readline().split()) l = div(q - p) ll = div(s - r) while True: if p == r and q == s: print(p,q) break d = q - p dd = s - r if d > dd: n = calc(p,q,l) g = gcd(p + n,q + n) p = (p + n) // g q = (q + n) // g elif dd > d: n = calc(r,s,ll) g = gcd(r + n,s + n) r = (r + n) // g s = (s + n) // g else: if q > s: s,q = q,s p,r = r,p l,ll = ll,l n = calc(p,q,l) if q + n > s: print(r,s) break else: g = gcd(p + n,q + n) p = (p + n) // g q = (q + n) // g