#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int N;
int P[100], Q[100], R[100], B[100];
int T[100];

long long gcd(long long a, long long b) {
  if (a > b) swap(a, b);
  if (a == 0) return b;
  return gcd(b%a, a);
}

long long lcm(long long a, long long b) {
  long long g = gcd(a, b);
  if (g == 0) return max(a, b);
  cout << "lcm("<<a<<", "<<b<<") = " << a/g*b<<"\n";
  return a / g * b;
}

long long f(int x) {
  if (x == -1) return 1;
  long long l = f(R[x]), r = f(B[x]);
  long long g = gcd(l*P[x], r*Q[x]);
  return l * r * (P[x] + Q[x]) / g;
}

int main() {
  while (cin >> N) {
    if (N == 0) break;
    for (int i=0; i<N; i++) T[i] = 0;
    for (int i=0; i<N; i++) {
      int r, b;
      cin >> P[i] >> Q[i] >> R[i] >> B[i];
      int g = gcd(P[i], Q[i]);
      P[i] /= g, Q[i] /= g;
      R[i]--, B[i]--;
      if (R[i] >= 0) T[R[i]]++;
      if (B[i] >= 0) T[B[i]]++;
    }
    int root = -1;
    for (int i=0; i<N; i++) {
      if (T[i] == 0) root = i;
    }
    cout << f(root) << "\n";
  }
  return 0;
}