n=*0...gets.to_i
g=n.map{gets.split.map &:to_i}.sort
r=g.reduce(n){|res,v|res-v[2,$$]}[0]
d=->f,i,x{g[i][1]=x
p [i,x]
g[i][2,$$].map{|i|f[f,i,x+1]}}
d[d,r,0]
g.map{|v|i,d,*c=v
g.map{|w|w[0]if w[2,$$].index i}.compact
[i,p=g.map{|w|w[0]if w[2,$$].index i}.compact[0]||-1,d,p<0?:root:c[0]?"internal node": :leaf,c]}.map{|v|puts"node %d: parent = %d, depth = %d, %s, %s"%v}