def search(depth, cur)
  @n.times do |i|
    next if @used[i]
    if @sendto[i] == cur
      @used[i] = true
      puts '.' * (depth + 1) + @msg[i]
      search(depth + 1, i)
    end
  end
end

@n = gets.to_i
@msg = @n.times.map{ '' }
@sendto = [-1] * @n
@n.times do |i|
  @sendto[i] = gets.to_i - 1
  @msg[i] = gets.chomp
end

@used = [false] * @n

puts @msg[0]
@used[0] = true
search(0, 0)