# ユークリッドの互除法で最大公約数を求める
def d(n,m)
  if m == 0
    n
  else
    d(m, n % m)
  end
end

# 棒の左右の最小重量から棒以下のモビールの重量を求める
def weight(bo)
  # boが錘である
  if bo[0] == 0
    return 1
  else
    w_red  = weight($boes[bo[2]])
    w_blue = weight($boes[bo[3]])
    l_red  = bo[0]
    l_blue = bo[1]
    m_min = l_red * l_blue * w_red * w_blue / d(l_red * w_red, l_blue * w_blue)
    return m_min/l_red + m_min/l_blue
  end
end

# main
loop do
  n = gets.to_i
  break if n == 0
  $boes = []*(n+1)
  $boes[0] = [0,0,0,0]
  for i in 1..n do
    $boes[i] = gets.split(" ").map(&:to_i)
  end

  # 一番上の棒を探す
  is_child = Array.new(n+1) {false}
  for i in 1..n do
    is_child[$boes[i][2]] = true
    is_child[$boes[i][3]] = true
  end
  top = is_child.index(false)

  # 一番上から再帰的にモビールの重量を求める
  res = weight($boes[top])
  puts res
end