loop do
    n = gets.to_i
    break if n == 0
    lines = (0..n-1).map { gets.chomp }

    stack = []
    (0..lines.size-1).each do |i|
        line = lines[i]
        level = line.count(?.)

        if stack.size > level
            j = stack.pop until stack.size == level
            if level > 0
                (j+1..i-1).each do |k|
                    lines[k] = ?. * (level - 1) + ?| + lines[k][level..-1]
                end
            end
        end
        stack << i
    end

    lines.each do |line|
        line.sub!(/\.(\w)/, '+\1')
        line.gsub!(/\./, ' ')
    end

    puts lines
end