import math from collections import defaultdict def Divisors(N): divisors=[] for i in range(1,N+1): if i**2>=N: break elif N%i==0: divisors.append(i) if i**2==N: divisors+=[i]+[N//i for i in divisors[::-1]] else: divisors+=[N//i for i in divisors[::-1]] return divisors Q=int(input()) for q in range(Q): a,b,c,d=map(int,input().split()) M=10**9 def tree(p,q): D=Divisors(q-p) def f(p,q): if q-p==1: return [((p,q),(M,M+1))] lst=[] for d in D[1:]: if (q-p)%d==0: lst.append((-p)%d) if lst: mi=min(lst) pp=p+mi qq=q+mi g=math.gcd(pp,qq) return [((p,q),(pp,qq))]+f(pp//g,qq//g) else: return [((p,q),(1,q-p+1))] return f(p,q) tree0=tree(a,b) tree1=tree(c,d) dct=defaultdict(list) for ((a0,b0),(c0,d0)) in tree0: dct[b0-a0].append((a0,c0)) for ((a1,b1),(c1,d1)) in tree1: dct[b1-a1].append((a1,c1)) lst=[] for d in dct: if len(dct[d])==2: (a0,c0),(a1,c1)=dct[d] a=max(a0,a1) c=min(c0,c1) if a<=c: lst.append((d,a)) d,a=min(lst) print(a,a+d)