import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### pmax = 31625 p = [-1] * pmax primes = [] for i in range(2, pmax): if p[i] == -1: primes.append(i) for j in range(i, pmax, i): p[j] = i def fac(x): ans = [] for p in primes: if x % p == 0: ans.append(p) while x % p == 0: x //= p if x != 1: return ans + [x] return ans def nxt(p, q, f): x = 10**18 for i in f: if (q-p) % i == 0: x = min(x, (p + i-1)//i*i-p) g = gcd(p+x,q+x) return (p+x)//g, (q+x)//g, x from math import gcd for _ in range(ni()): p1, q1, p2, q2 = na() f1 = fac(q1-p1) f2 = fac(q2-p2) while True: #print(p1,q1,p2,q2) if q1-p1 == q2-p2: if q1 > q2: q1,q2 = q2,q1 p1,p2 = p2,p1 f1,f2 = f2,f1 p3,q3,x = nxt(p1, q1, f1) if q1 + x >= q2: print(p2, q2) break p1, q1 = p3, q3 elif q1 - p1 > q2 - p2: q1,q2 = q2,q1 p1,p2 = p2,p1 f1,f2 = f2,f1 p3, q3, x = nxt(p2, q2, f2) p2, q2 = p3, q3