n = int(input())
vert = [[0,0]+list(map(int,range(1,n+1)))]
parents = [0]
now = 0
time = 0
for i in range(n):
    ukv = list(map(int,input().split()))
    vert.append([0,0]+ukv[2:])
while(parents):
    for i in range(2,len(vert[now])):
        if vert[vert[now][i]][0] == 0:
            parents.append(now)
            now = vert[now][i]
            time += 1
            vert[now][0] = time
            break
    else:
        if now != 0:
            time += 1
        vert[now][1] = time
        now = parents.pop()
for i in range(1,n+1):
    print(i,*vert[i][0:2]) n = int(input()) n int(input()) int input() input vert = [[0,0]+list(map(int,range(1,n+1)))] vert [[0,0]+list(map(int,range(1,n+1)))] [0,0]+list(map(int,range(1,n+1))) [0,0] 0 0 list(map(int,range(1,n+1))) list map(int,range(1,n+1)) map int range(1,n+1) range 1 n+1 n 1 parents = [0] parents [0] 0 now = 0 now 0 time = 0 time 0 for i in range(n):
    ukv = list(map(int,input().split()))
    vert.append([0,0]+ukv[2:]) i range(n) range n ukv = list(map(int,input().split())) ukv list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split vert.append([0,0]+ukv[2:]) vert.append vert append [0,0]+ukv[2:] [0,0] 0 0 ukv[2:] ukv 2: 2 while(parents):
    for i in range(2,len(vert[now])):
        if vert[vert[now][i]][0] == 0:
            parents.append(now)
            now = vert[now][i]
            time += 1
            vert[now][0] = time
            break
    else:
        if now != 0:
            time += 1
        vert[now][1] = time
        now = parents.pop() parents for i in range(2,len(vert[now])):
        if vert[vert[now][i]][0] == 0:
            parents.append(now)
            now = vert[now][i]
            time += 1
            vert[now][0] = time
            break
    else:
        if now != 0:
            time += 1
        vert[now][1] = time
        now = parents.pop() i range(2,len(vert[now])) range 2 len(vert[now]) len vert[now] vert now if vert[vert[now][i]][0] == 0:
            parents.append(now)
            now = vert[now][i]
            time += 1
            vert[now][0] = time
            break
     vert[vert[now][i]][0] == 0 vert[vert[now][i]][0] [vert[now][i]] vert vert[now][i] [now] vert now i 0 0 parents.append(now) parents.append parents append now now = vert[now][i] now vert[now][i] [now] vert now i time += 1 time 1 vert[now][0] = time vert[now][0] [now] vert now 0 time break if now != 0:
            time += 1
         now != 0 now 0 time += 1 time 1 vert[now][1] = time vert[now][1] [now] vert now 1 time now = parents.pop() now parents.pop() parents.pop parents pop for i in range(1,n+1):
    print(i,*vert[i][0:2]) i range(1,n+1) range 1 n+1 n 1 print(i,*vert[i][0:2]) print i *vert[i][0:2] vert[i][0:2] [i] vert i 0:2 0 2 time += 1 1 time now = parents.pop() parents.pop() now ukv = list(map(int,input().split())) list(map(int,input().split())) ukv vert = [[0,0]+list(map(int,range(1,n+1)))] [[0,0]+list(map(int,range(1,n+1)))] vert now = vert[now][i] vert[now][i] now n = int(input()) int(input()) n parents = [0] [0] parents time = 0 0 time now = 0 0 now time += 1 1 time
n = int(input())
vert = [[0,0]+list(map(int,range(1,n+1)))]
parents = [0]
now = 0
time = 0
for i in range(n):
    ukv = list(map(int,input().split()))
    vert.append([0,0]+ukv[2:])
while(parents):
    for i in range(2,len(vert[now])):
        if vert[vert[now][i]][0] == 0:
            parents.append(now)
            now = vert[now][i]
            time += 1
            vert[now][0] = time
            break
    else:
        if now != 0:
            time += 1
        vert[now][1] = time
        now = parents.pop()
for i in range(1,n+1):
    print(i,*vert[i][0:2])
