

#include <stdio.h>
#include <string.h>
#include <algorithm>

using ll = long long int;

ll gcd(ll a_, ll b_)
{
	if (b_ == 0)return a_;
	return gcd(b_, a_% b_);
}

const ll MAX_N = 100;
ll memo[MAX_N + 1];
ll p[MAX_N + 1], q[MAX_N + 1];
ll r[MAX_N + 1], b[MAX_N + 1];
ll n;
ll dp(int x_)
{
	if (memo[x_] > 0)return memo[x_];
	dp(r[x_]); dp(b[x_]);
	ll a_ = memo[r[x_]]; ll b_ = memo[b[x_]];
	ll c_ = p[x_] / gcd(p[x_], q[x_]);
	ll d_ = q[x_] / gcd(p[x_], q[x_]);
	return memo[x_] = a_ * b_ * (c_ + d_) / gcd(a_*c_, b_*d_);
}

int main()
{
	for (;;)
	{
		scanf("%lld",&n);
		if (n == 0)break;
		for (int i = 1; i <= n; ++i)scanf("%lld %lld %lld %lld",p + i,q + i,r + i,b + i);
		memset(memo, 0, sizeof(memo));
		memo[0] = 1;
		ll ans = 0;
		for (int i = 1; i <= n; ++i)
		{
			ans = std::max(dp(i),ans);
		}
		printf("%d\n",ans);
	}
	return 0;
}