class Tree
    def initialize
        @children = []
    end

    def show(indent = 0)
        puts ?. * indent + name
        @children.each {|c| c.show(indent + 1)}
    end
    attr_accessor :children, :name
end

n = gets.to_i
a = (0..n).map{Tree.new}

(1..n).each do |i|
    a[gets.to_i].children << a[i]
    a[i].name = gets.chomp
end

a[1].show