def calc(i)
    case $char[i]
    when "*"
        $children[i].inject(1) {|r, v| r * calc(v)}
    when "+"
        $children[i].inject(0) {|r, v| r + calc(v)}
    else
        $char[i].to_i
    end
end

loop do
    break if (l = gets.to_i) == 0

    $char = Array.new(l)
    $char[0] = gets.chomp
    $children = Array.new(l){[]}

    (l-1).times do |i|
        i += 1
        s = gets.chomp
        n = s.count(".")

        now = 0
        (n-1).times {now = $children[now][-1]}

        $children[now] << i
        $char[i] = s[-1]
    end
    
    puts calc(0)
end
