def DFS(num):
    global time
    time +=1
    color[num]="gray"
    D[num][0]=time
    for i in M[num]:
        if color[i]=="white":
            DFS(i)
    color[num]="black"
    time +=1
    D[num][1]=time


n=int(input())
M=[[] for _ in range(n+1)]
for i in range(n):
    for j in list(map(int,input().split()))[2:]:
        M[i+1].append(j)
color=["white" for _ in range(n+1)]
D=[[0,0] for _ in range(n+1)]
time=0
for i in range(n):
    if color[i+1]=="white":
        DFS(i+1)

for i in range(n):
    print(i+1,*D[i+1]) def DFS(num):
    global time
    time +=1
    color[num]="gray"
    D[num][0]=time
    for i in M[num]:
        if color[i]=="white":
            DFS(i)
    color[num]="black"
    time +=1
    D[num][1]=time DFS global time time +=1 time 1 color[num]="gray" color[num] color num "gray" D[num][0]=time D[num][0] [num] D num 0 time for i in M[num]:
        if color[i]=="white":
            DFS(i)
     i M[num] M num if color[i]=="white":
            DFS(i)
     color[i]=="white" color[i] color i "white" DFS(i) DFS i color[num]="black" color[num] color num "black" time +=1 time 1 D[num][1]=time D[num][1] [num] D num 1 time num num n=int(input()) n int(input()) int input() input [] for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [] M=[[] for _ in range(n+1)] M [[] for _ in range(n+1)] for i in range(n):
    for j in list(map(int,input().split()))[2:]:
        M[i+1].append(j) i range(n) range n for j in list(map(int,input().split()))[2:]:
        M[i+1].append(j) j list(map(int,input().split()))[2:] (map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split 2: 2 M[i+1].append(j) [i+1].append [i+1] M i+1 i 1 append j "white" for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) "white" color=["white" for _ in range(n+1)] color ["white" for _ in range(n+1)] [0,0] for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [0,0] 0 0 D=[[0,0] for _ in range(n+1)] D [[0,0] for _ in range(n+1)] time=0 time 0 for i in range(n):
    if color[i+1]=="white":
        DFS(i+1) i range(n) range n if color[i+1]=="white":
        DFS(i+1) color[i+1]=="white" color[i+1] color i+1 i 1 "white" DFS(i+1) DFS i+1 i 1 for i in range(n):
    print(i+1,*D[i+1]) i range(n) range n print(i+1,*D[i+1]) print i+1 i 1 *D[i+1] D[i+1] D i+1 i 1 D=[[0,0] for _ in range(n+1)] [[0,0] for _ in range(n+1)] D time=0 0 time n=int(input()) int(input()) n color=["white" for _ in range(n+1)] ["white" for _ in range(n+1)] color def DFS(num):
    global time
    time +=1
    color[num]="gray"
    D[num][0]=time
    for i in M[num]:
        if color[i]=="white":
            DFS(i)
    color[num]="black"
    time +=1
    D[num][1]=time def DFS(num):
    global time
    time +=1
    color[num]="gray"
    D[num][0]=time
    for i in M[num]:
        if color[i]=="white":
            DFS(i)
    color[num]="black"
    time +=1
    D[num][1]=time DFS M=[[] for _ in range(n+1)] [[] for _ in range(n+1)] M
def DFS(num):
    global time
    time +=1
    color[num]="gray"
    D[num][0]=time
    for i in M[num]:
        if color[i]=="white":
            DFS(i)
    color[num]="black"
    time +=1
    D[num][1]=time


n=int(input())
M=[[] for _ in range(n+1)]
for i in range(n):
    for j in list(map(int,input().split()))[2:]:
        M[i+1].append(j)
color=["white" for _ in range(n+1)]
D=[[0,0] for _ in range(n+1)]
time=0
for i in range(n):
    if color[i+1]=="white":
        DFS(i+1)

for i in range(n):
    print(i+1,*D[i+1])
