import math def compute_base(p, q): d = q - p while d > 1: g = math.gcd(p + 1, q + 1) new_p = (p + 1) // g new_q = (q + 1) // g p, q = new_p, new_q d = q - p return (p, q) Q = int(input()) for _ in range(Q): p1, q1, p2, q2 = map(int, input().split()) # Compute base nodes base1_p, base1_q = compute_base(p1, q1) base2_p, base2_q = compute_base(p2, q2) # Compare the base nodes if (base1_p, base1_q) == (base2_p, base2_q): l_p, l_q = base1_p, base1_q else: # In the difference 1 phase, the LCA is the one with larger p if base1_p > base2_p: l_p, l_q = base1_p, base1_q else: l_p, l_q = base2_p, base2_q print(l_p, l_q)