#include <iostream>
#include <algorithm>
#include <utility>
#include <cstring>
using namespace std;

int dp[110],K[110],O[110],L[110],R[110];

int gcd(int a,int b){
	int tmp;
	if(a<b) swap(a,b);
	while((tmp=a%b)!=0){
		a=b;
		b=tmp;
	}
	return b;
}


int mobi(int bou){
	if(bou==0) return 1;
	if(dp[bou]!=0) return dp[bou];
	int l,r,li,ri,gc2,a,b;
	l=mobi(L[bou]);
	r=mobi(R[bou]);
	li=K[bou];ri=O[bou];
	gc2=gcd(li*l,ri*r);
	b=(li*l)/gc2;
	a=(ri*r)/gc2;
	dp[bou]=(a*l+b*r);
	return dp[bou];
}

int main(){
	int N,k,o,g;
	int res;
	while(1){
		cin>>N;
		if(N==0) break;
		memset(dp,0,sizeof(dp));
		K[0]=O[0]=L[0]=R[0]=0;
		for(int i=1;i<=N;i++){
			cin>>k>>o>>L[i]>>R[i];
			g=gcd(k,o);
			K[i]=k/g;
			O[i]=o/g;
		}
		res=0;
		for(int i=1;i<=N;i++){
			res=max(res,mobi(i));
		}
		/*
		for(int i=1;i<=N;i++){
			cout<<i<<" "<<dp[i]<<endl;//
		}
		*/
		cout<<res<<endl;
	}
	return 0;
}