#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef std::pair pii; typedef std::pair pli; typedef std::pair pll; #define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i) #define REP(i,n) FOR(i,n,0) #define IREP(i,n) for(ll i=(ll)(n);i>=0;--i) #define OF64 std::setprecision(10) const ll MOD = 1000000007; const ll INF = (ll)1e15; pair P[20]; int n(int a, int b) { if (a < b) { swap(a, b); } int c = a%b; if (c == 0)return b; return n(b, c); } int main() { int N; cin >> N; REP(i, N) { cin >> P[i].first >> P[i].second; } sort(P, P + N, [](pair a, pair b) {return a.first / a.second > b.first / b.second; }); REP(i, N) { int a = (int)P[i].first, b = (int)P[i].second; if (a == 0) { cout << a << " " << b << endl; } else { int t = n(abs(a), abs(b)); cout << a / t << " " << b / t << endl; } } return 0; }