Problem:
Nathan O. Davis has been running an electronic bulletin board system named JAG-channel. He is now having hard time to add a new feature there --- threaded view. Like many other bulletin board systems, JAG-channel is thread-based. Here a thread (also called a topic) refers to a single conversation with a collection of posts. Each post can be an opening post, which initiates a new thread, or a reply to a previous post in an existing thread. Threaded view is a tree-like view that reflects the logical reply structure among the posts: each post forms a node of the tree and contains its replies as its subnodes in the chronological order (i.e. older replies precede newer ones). Note that a post along with its direct and indirect replies forms a subtree as a whole. Let us take an example. Suppose: a user made an opening post with a message hoge ; another user replied to it with fuga ; yet another user also replied to the opening post with piyo ; someone else replied to the second post (i.e. fuga ”) with foobar ; and the fifth user replied to the same post with jagjag .
The tree of this thread would look like: hoge
├─fuga
│　├─foobar
│　└─jagjag
└─piyo For easier implementation, Nathan is thinking of a simpler format: the depth of each post from the opening post is represented by dots. Each reply gets one more dot than its parent post. The tree of the above thread would then look like:  hoge
.fuga
..foobar
..jagjag
.piyo  Your task in this problem is to help Nathan by writing a program that prints a tree in the Nathan's format for the given posts in a single thread.  Input  Input contains a single dataset in the following format:   n  k_1  M_1  k_2  M_2 :
: k_n  M_n   The first line contains an integer n ( 1 ≤ n ≤ 1,000 ), which is the number of posts in the thread.
Then 2n lines follow.
Each post is represented by two lines:
the first line contains an integer k_i ( k_1 = 0 , 1 ≤ k_i < i for 2 ≤ i ≤ n ) and indicates the i -th post is a reply to the k_i -th post;
the second line contains a string M_i and represents the message of the i -th post. k_1 is always 0, which means the first post is not replying to any other post, i.e. it is an opening post.  Each message contains 1 to 50 characters, consisting of uppercase, lowercase, and numeric letters.  Output  Print the given n messages as specified in the problem statement.  Sample Input 1  1
0
icpc  Output for the Sample Input 1  icpc  Sample Input 2  5
0
hoge
1
fuga
1
piyo
2
foobar
2
jagjag  Output for the Sample Input 2  hoge
.fuga
..foobar
..jagjag
.piyo  Sample Input 3  8
0
jagjag
1
hogehoge
1
buhihi
2
fugafuga
4
ponyoponyo
5
evaeva
4
nowawa
5
pokemon  Output for the Sample Input 3  jagjag
.hogehoge
..fugafuga
...ponyoponyo
....evaeva
....pokemon
...nowawa
.buhihi  Sample Input 4  6
0
nakachan
1
fan
2
yamemasu
3
nennryou2
4
dannyaku4
5
kouzai11  Output for the Sample Input 4  nakachan
.fan
..yamemasu
...nennryou2
....dannyaku4
.....kouzai11  Sample Input 5  34
0
LoveLive
1
honoka
2
borarara
2
sunohare
2
mogyu
1
eri
6
kasikoi
7
kawaii
8
eriichika
1
kotori
10
WR
10
haetekurukotori
10
ichigo
1
umi
14
love
15
arrow
16
shoot
1
rin
18
nyanyanya
1
maki
20
6th
20
star
22
nishikino
1
nozomi
24
spiritual
25
power
1
hanayo
27
darekatasukete
28
chottomattete
1
niko
30
natsuiro
30
nikkonikkoni
30
sekaino
33
YAZAWA  Output for the Sample Input 5  LoveLive
.honoka
..borarara
..sunohare
..mogyu
.eri
..kasikoi
...kawaii
....eriichika
.kotori
..WR
..haetekurukotori
..ichigo
.umi
..love
...arrow
....shoot
.rin
..nyanyanya
.maki
..6th
..star
...nishikino
.nozomi
..spiritual
...power
.hanayo
..darekatasukete
...chottomattete
.niko
..natsuiro
..nikkonikkoni
..sekaino
...YAZAWA  Sample Input 6  6
0
2ch
1
1ostu
1
2get
1
1otsu
1
1ostu
3
pgr  Output for the Sample Input 6  2ch
.1ostu
.2get
..pgr
.1otsu
.1ostu

Solution (Python):
import sys
sys.setrecursionlimit(9999)
def dfs(i, z):
    print "." * z + name[i]
    for j in child[i]:
        dfs(j, z + 1)

n = int(raw_input())
name = []
child = [[] for i in xrange(n)]
for i in xrange(n):
    k = int(raw_input())
    m = raw_input()
    name.append(m)
    if k == 0: continue
    child[k - 1].append(i)

dfs(0, 0)

Solution (Python):
import sys
sys.setrecursionlimit(10000)
n=int(input())
a=[]
b=[[]for _ in [0]*n]

def f(i,x):
    print('.'*x+a[i])
    for j in b[i]:
        f(j,x+1)

for i in range(n):
    c=int(input())
    a+=[input()]
    if c!=0:b[c-1]+=[i]
f(0,0)

Solution (Python):
import sys
sys.setrecursionlimit(1010)

N = int(input())
src = []
for i in range(N):
    k = int(input())
    s = input()
    src.append((s,[]))
    if i == 0: continue
    src[k-1][1].append(i)

def dfs(i,depth):
    s,ch = src[i]
    print('.'*depth + s)
    for c in ch:
        dfs(c,depth+1)

dfs(0,0)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    while True:
        n = I()
        a = []
        e = collections.defaultdict(list)
        for i in range(n):
            k = I()
            l = S()
            e[k].append(i+1)
            a.append(l)
        f = [None] * n
        def ff(i,d):
            f[i-1] = 1
            r = ['.' * d + a[i-1]]
            for j in e[i]:
                r += ff(j,d+1)
            return r
        for i in range(n):
            if f[i]:
                continue
            rr += ff(i+1,0)

        break



    return '\n'.join(map(str, rr))


print(main())

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n,h,w = LI()
    x = LI()
    t = [0 for i in range(w*n+1)]
    for i in range(n):
        if not i%2:
            t[i*w+x[i]] += 1
            t[(i+1)*w+x[i]] -= 1
        else:
            t[i*w-x[i]] += 1
            t[(i+1)*w-x[i]] -= 1
    for i in range(w*n):
        t[i+1] += t[i]
    ans = 0
    for i in t[:-1]:
        if i == 0:
            ans += h
    print(ans)
    return


def B():
    def dfs(d,x):
        for i in range(d):
            print(".",end = "")
        print(lis[x])
        for y in v[x]:
            dfs(d+1,y)

    n = I()
    v = [[] for i in range(n)]
    lis = [None for i in range(n)]
    for i in range(n):
        k = I()
        lis[i] = input()
        if k > 0:
            v[k-1].append(i)
    dfs(0,0)
    return


def C():
    return


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


def I_():
    return


def J():
    return


if __name__ == "__main__":
    B()