var n;
var t = [];

function gcd(a, b){
	return b > 0 ? gcd(b, a % b) : a;
}

function solve(i){
	if(i == -1){
		return 1;
	}

	var a = solve(t[i][2]);
	var b = solve(t[i][3]);
	var c = gcd(a, t[i][0]);
	var d = gcd(b, t[i][1]);
	var p = a / c;
	var q = b / d;
	var g = gcd(p, q);
	return (p * q / g) * (t[i][0] + t[i][1]);
}

function main(){
	while(n = scan()){
		rep(n, function(i){
			var a = scan();
			var b = scan();
			var g = gcd(a, b);
			t[i] = [b / g, a / g, scan() - 1, scan() - 1];
		});
		var c = [];
		rep(n, function(i){
			c[t[i][2]] = c[t[i][3]] = true;
		});
		var p;
		rep(n, function(i){
			if(!c[i]){
				p = i;
			}
		});
		print(solve(p));
	}
}
 
function rep(a, b, c){
	if(c === undefined){
		c = b;
		b = a;
		a = 0;
	}
	for(var i = a; i < b; ++i){
		if(c(i) === false){
			break;
		}
	}
}
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var input = '';
var input_index = 0;
 
function scan(type){
	if(type === 'string'){
		return input[input_index++];
	}
	else{
		return +input[input_index++];
	}
}
 
function print(val){
	console.log(val);
}
 
process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.trim().split(/\s+/);
	main();
});