class Tree
    def initialize(*args)
        @val, @parent = args
        @depth = (parent ? parent.depth + 1 : 1)
        @children = []
        @parent.children << self if @parent
    end
    def eval
        return @val.to_i if @val =~ /\d/
        @children.map {|c| c.eval}.inject(@val.to_sym)
    end
    attr_reader :parent, :children, :depth
end

loop do
    n = gets.to_i
    break if n == 0
    root = v = nil
    n.times do
        gets =~ /(\.*)(.+)/
        depth, x = $1.size, $2
        v = v.parent until !v || depth == v.depth
        v = Tree.new(x, v)
        root ||= v
    end
    p root.eval
end