#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  while(true){
    scanf("%d", &n);

    if(n == 0) break;

    vector<int> d(n), v(n);
    REP(i,n){
      scanf("%d %d", &d[i], &v[i]);
      FOR(j,2,10001){
        while(d[i] % j == 0 && v[i] % j == 0){
          d[i] /= j; v[i] /= j;
        }
      }
    }

    map<llong, int> mp;
    REP(i,n){
      map<llong, int> a, b;
      int tmp = v[i];
      for(int j = 2; j <= v[i]; ++j){
        while(tmp % j == 0){
          a[j]++;
          tmp /= j;
        }
      }
      tmp = d[i];
      for(int j = 2; j <= d[i]; ++j){
        while(tmp % j == 0){
          b[j]++;
          tmp /= j;
        }
      }

      REPI(itr,b){
        itr->second = max(0, itr->second - a[itr->first]);
        if(mp.find(itr->first) != mp.end()){
          mp[itr->first] = itr->second;
        }else{
          mp[itr->first] = max(mp[itr->first], itr->second);
        }
      }
    }
    bool f = true;
    FOR(i,1,n){
      if(d[i] != d[0] || v[i] != v[0]){
        f = false;
        break;
      }  
    }
    if(f){
      REP(i,n){
        printf("1\n");
      }
      continue;
    }

    llong D = 1;
    REPI(itr,mp){
      cout << itr->first << " " << itr->second <<  endl;
      D *= pow(itr->first, itr->second);
    }
    
    REP(i,n){
      printf("%lld\n", D / d[i] * v[i]);
    }
  }

  return 0;
}


