#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    LL n;
    cin >> n;
    vector<pair<LL,LL>> x;

    LL y = 1;

    for(int i = 0; i < n; i++){
        LL a,b;
        cin >> a >> b;
        x.push_back(make_pair(a,b));
        y *= b;
    }

    for(int i = 0; i < n; i++){
        x[i].first *= (y/x[i].second);
    }

    sort(x.begin(),x.end());

    for(int i = n-1; i >= 0; i--){
        cout << x[i].first/((y/x[i].second)) << " ";
        cout << x[i].second << endl;
    }
    
    return 0;
}