#include <iostream>
#include <cassert>
using namespace std;
typedef long long ll;
int N,cnt[110] = {};
ll p[110],q[110],r[110],b[110],dp[110] = {};

ll gcd(ll n,ll m){
    assert(n!=0);
    assert(m!=0);
    if(n%m==0) return m;
    else return gcd(m,n%m);
}

void dfs(int n){
    if(n==0){
        dp[0] = 1;
    }else{
        dfs(r[n]); dfs(b[n]);
        assert(dp[r[n]] != 0);
        assert(dp[b[n]] != 0);
        assert(p[n] != 0);
        assert(q[n] != 0);
        ll g = gcd(dp[r[n]]*p[n],dp[b[n]]*q[n]);
        assert(g!=0);
        dp[n] = (dp[r[n]]*p[n])/g*dp[b[n]]+(dp[b[n]]*q[n])/g*dp[r[n]];
    }
    assert(dp[n]!=0);
}

int main(){
    while((cin >> N) && (N>0)){
        int par;
        for(int i=0;i<=N;i++) cnt[i] = 0;
        for(int i=1;i<=N;i++){
            cin >> p[i] >> q[i] >> r[i] >> b[i];
            cnt[r[i]]++; cnt[b[i]]++;
        }
        for(int i=1;i<=N;i++) if(cnt[i]==0) par = i;
        dfs(par);
        cout << dp[par] << endl;
    }
}
