class Tree
    def initialize(val, parent)
        @val, @parent = val, parent
        @depth = (parent ? parent.depth + 1 : 1)
        @children = []
        @parent.children << self if @parent
    end

    def eval
        return @val.to_i if @val =~ /\d/
        return @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

    parent = {}
    root = nil
    v = nil
    n.times do
        gets.chomp =~ /(\.*)(.+)/
        indent = $1.size
        v = v.parent until !v || indent == v.depth
        x = $2
        v = Tree.new(x, v)
        root ||= v
    end
    p root.eval
end