class Node():
    def __init__(self, id, left, right, parent=-1, sibling=-1, degree=-1, depth=-1, height=-1, type=None):
        self.id = id
        self.left = left
        self.right = right
        self.parent = parent
        self.sibling = sibling
        self.degree = degree
        self.depth = depth
        self.height = height
        self.type = type
    def show(self):
        print 'node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s' % (self.id, self.parent, self.sibling, self.degree, self.depth, self.height, self.type)

def hasChild(x):
    if x == -1:
        return 0
    else:
        return 1

def calcDepth(node):
    if node.parent == -1:
        return 0
    return 1 + calcDepth(a[node.parent])

def calcHeight(node):
    if node.degree == 0:
        return 0
    return 1 + max(calcHeight(a[node.left]), calcHeight(a[node.right]))

n = int(raw_input())
a = []
for i in range(n):
    tmp = map(int, raw_input().split())
    if tmp[1] == -1 and tmp[2] == -1:
        a.append(Node(tmp[0], tmp[1], tmp[2], degree=0, type='leaf'))
    else:
        a.append(Node(tmp[0], tmp[1], tmp[2], degree=hasChild(tmp[1])+hasChild(tmp[2])))

for i in range(n):
    if a[i].right != -1:
        a[a[i].right].parent = a[i].id
    if a[i].left != -1:
        a[a[i].left].parent = a[i].id

for i in range(n):
    a[i].depth = calcDepth(a[i])
    a[i].height = calcHeight(a[i])
        
for i in range(n):
    if a[i].parent != -1 and a[i].degree != 0:
        a[i].type = 'internal node'
    elif a[i].parent == -1 and a[i].degree > 0:
        a[i].type = 'root'
    for j in range(n):
        if i == j:
            continue
        if a[i].depth == a[j].depth and a[i].parent == a[j].parent:
            a[i].sibling = j
        
for el in a:
    el.show()

### FIXED CODE ###

class Node():
    def __init__(self, id, left, right, parent=-1, sibling=-1, degree=-1, depth=-1, height=-1, type=None):
        self.id = id
        self.left = left
        self.right = right
        self.parent = parent
        self.sibling = sibling
        self.degree = degree
        self.depth = depth
        self.height = height
        self.type = type
    def show(self):
        print 'node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s' % (self.id, self.parent, self.sibling, self.degree, self.depth, self.height, self.type)

def hasChild(x):
    if x == -1:
        return 0
    else:
        return 1

def calcDepth(node):
    if node.parent == -1:
        return 0
    return 1 + calcDepth(a[node.parent])

def calcHeight(node):
    if node.degree == 0:
        return 0
    return 1 + max(calcHeight(a[node.left]), calcHeight(a[node.right]))

n = int(raw_input())
a = []
dict = {}
for i in range(n):
    tmp = map(int, raw_input().split())
    if tmp[1] == -1 and tmp[2] == -1:
        dict[tmp[0]] = Node(tmp[0], tmp[1], tmp[2], degree=0)
    else:
        dict[tmp[0]] = Node(tmp[0], tmp[1], tmp[2], degree=hasChild(tmp[1])+hasChild(tmp[2]))

for i in range(n):
    a.append(dict[i])

for i in range(n):
    if a[i].right != -1:
        a[a[i].right].parent = a[i].id
    if a[i].left != -1:
        a[a[i].left].parent = a[i].id

for i in range(n):
    a[i].depth = calcDepth(a[i])
    a[i].height = calcHeight(a[i])
        
for i in range(n):
    if a[i].parent != -1 and a[i].degree != 0:
        a[i].type = 'internal node'
    elif a[i].parent != -1 and a[i].degree == 0:
        a[i].type = 'leaf'
    else:
        a[i].type = 'root'
        
    for j in range(n):
        if i == j:
            continue
        if a[i].depth == a[j].depth and a[i].parent == a[j].parent:
            a[i].sibling = j
        
for el in a:
    el.show()