#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> 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<double, double> 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<double, double> a, pair<double, double> 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;
}