#include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int Q; cin >> Q; while(Q--){ int p0, q0, p1, q1; cin >> p0 >> q0 >> p1 >> q1; auto ope = [&](int &p, int &q, int d){ int p2 = p0 ^ p1 ^ p, q2 = q0 ^ q1 ^ q; int d2 = q2 - p2; int di = d - p % d; if(d == d2 && p2 <= p + di){ p = p2, q = q2; return; } p += di, q += di; int g = __gcd(p, q); p /= g, q /= g; }; while(p0 != p1 || q0 != q1){ int d0 = q0 - p0; int d1 = q1 - p1; if(d0 == 1 && d1 == 1){ p0 = max(p0, p1); q0 = p0 + 1; break; } if(d0 > d1 || (d0 == d1 && p0 < p1)){ ope(p0, q0, d0); }else{ ope(p1, q1, d1); } } cout << p0 << " " << q0 << '\n'; } }