#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100;

int n;
ll p[MAX_N + 1], q[MAX_N + 1]; int r[MAX_N + 1], b[MAX_N + 1];
bool is_root[MAX_N + 1];

ll GCD(ll a, ll b){
	if(b == 0) return a;
	else return GCD(b, a % b);
}
ll LCM(ll a, ll b){
	return a / GCD(a, b) * b;
}

ll rec(int parent, bool is_red){
	if(is_red && parent == 0) return 1LL;
	if(!is_red && parent == 0) return 1LL;
	return LCM(rec(r[parent], true) * p[parent], rec(b[parent], false) * q[parent]) / p[parent] + LCM(rec(r[parent], true) * p[parent], rec(b[parent], false) * q[parent]) / q[parent];
}

int main(){
	for(;;){
		scanf("%d", &n);
		if(n == 0) break;
		fill(is_root, is_root + n + 1, true);
		for(int i = 1; i <= n; i++){
			scanf("%lld %lld %d %d", &p[i], &q[i], &r[i], &b[i]);
			is_root[r[i]] = false;
			is_root[b[i]] = false;
		}
		int root;
		for(int i = 1; i <= n; i++){
			if(is_root[i]) root = i;
		}
		printf("%lld\n", LCM(rec(r[root], true) * p[root], rec(b[root], false) * q[root]) / p[root] + LCM(rec(r[root], true) * p[root], rec(b[root], false) * q[root]) / q[root]);
	}
	return 0;
}

