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 prime = [] C = 4 * 10 ** 4 dat = [0] *C for i in range(2,C): if dat[i] == 0: prime.append(i) for j in range(i,C,i): dat[j] = 1 #print(prime[:20]) def div(d): l = [] for p in prime: if p > d:break if d % p == 0: l.append(p) d //= p while d % p == 0: d //= p if d > 1:l.append(d) return 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