import math import pypyjit pypyjit.set_param('max_unroll_recursion=-1') 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**18 def tree(p,q): D=Divisors(q-p) def f(p,q): if q-p==1: return [(1,p,M)] lst=[] for d in D[1:]: if (q-p)%d==0: lst.append((-p)%d) mi=min(lst) pp=p+mi qq=q+mi g=math.gcd(pp,qq) return [(q-p,p,pp)]+f(pp//g,qq//g) return f(p,q) tree0=tree(a,b) tree1=tree(c,d) assert len(tree0)<=30 assert len(tree1)<=30 D,A=M,M tree0.sort() tree1.sort() while tree0 and tree1: if tree0[-1][0]tree1[-1][0]: tree0.pop() else: d0,a0,b0=tree0.pop() d1,a1,b1=tree1.pop() a=max(a0,a1) b=min(b0,b1) d=d0 if a<=b: D,A=min((D,A),(d,a)) print(A,A+D)