#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std;
LL n;
LL p[111];
LL q[111];
LL r[111];
LL b[111];
LL m[111];

LL GCD(LL x,LL y){
  if(x < y) x^=y^=x^=y;
  LL r = x % y;
  if(r) return GCD(y,r);
  else return y;
}

LL solve(int k){
  if(k == 0) return 1;
  if(m[k]) return m[k];
  LL rm = solve(r[k]) * p[k];
  LL bm = solve(b[k]) * q[k];
  LL l = rm * bm / GCD(rm,bm);
  //cout << "k = " << k << " : " << l/p[k] << " + " << l/q[k] << endl;
  return m[k] = l/p[k] + l/q[k];
}

int main(void){
  while(cin >> n && n){
    memset(p,0,sizeof(p));
    memset(q,0,sizeof(q));
    memset(r,0,sizeof(r));
    memset(b,0,sizeof(b));
    memset(m,0,sizeof(m));
    for(int i = 1; i <= n; i++){
      cin >> p[i] >> q[i] >> r[i] >> b[i];
      LL g = GCD(p[i],q[i]);
      p[i] /= g;
      q[i] /= g;
    }
    LL res = 0;
    for(int i = 1; i <= n; i++){
      res = max(res,solve(i));
    }
    cout << res << endl;
  }
}