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

#define INF_LL 1e18
#define INF 1e9

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()

#define fst first
#define snd second

using namespace std;

using ll = long long;
using PII = pair<int, int>;

struct stick{
	int l_d, r_d;
	int par, l, r;
};

stick s[101];

ll gcd(ll x, ll y){
	if(y == 0) return x;
	return gcd(y, x%y);
}

ll dfs(ll st){
	if(st == 0) return 1;
	ll l_w = dfs(s[st].l);
	ll r_w = dfs(s[st].r);
	ll res = (l_w*r_w*s[st].l_d*s[st].r_d)/gcd(l_w*s[st].l_d, r_w*s[st].r_d);
	res = res/s[st].l_d + res/s[st].r_d;
	return res;
}

int main(void){
	int n;

	while(cin >> n && n){
		memset(s, 0, sizeof s);
		FOR(i, 1, n+1){
			s[i].par = i;
		}
		FOR(i, 1, n+1){
			int a;
			cin >> s[i].l_d >> s[i].r_d >> s[i].l >> s[i].r;
			a = gcd(s[i].l_d, s[i].r_d);
			s[i].l_d /= a;
			s[i].r_d /= a;
			s[s[i].l].par = i;
			s[s[i].r].par = i;
		}
		int start = 1;
		while(s[start].par != start){
			start = s[start].par;
		}
		cout << dfs(start) << endl;
	}
}