global graph
global seen
token=0

def dfs(i):
    global token
    token+=1
    seen[i][0]=token
    for x in graph[i]:
        if seen[x][0]==0:
            dfs(x)
    token+=1
    seen[i][1]=token


n=int(input())

graph=[None for _ in range(n+1)]

for i in range(n):
    lst=list(map(int,input().split()))
    graph[lst[0]]=lst[2:]

seen=[[0,0] for _ in range(n+1)]

for i in range(1,n+1):
    if seen[i][0]==0:
        dfs(i)

for i in range(1,n+1):
    print("{} {} {}".format(i,seen[i][0],seen[i][1])) global graph global seen token=0 token 0 def dfs(i):
    global token
    token+=1
    seen[i][0]=token
    for x in graph[i]:
        if seen[x][0]==0:
            dfs(x)
    token+=1
    seen[i][1]=token dfs global token token+=1 token 1 seen[i][0]=token seen[i][0] [i] seen i 0 token for x in graph[i]:
        if seen[x][0]==0:
            dfs(x)
     x graph[i] graph i if seen[x][0]==0:
            dfs(x)
     seen[x][0]==0 seen[x][0] [x] seen x 0 0 dfs(x) dfs x token+=1 token 1 seen[i][1]=token seen[i][1] [i] seen i 1 token i i n=int(input()) n int(input()) int input() input None for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) None graph=[None for _ in range(n+1)] graph [None for _ in range(n+1)] for i in range(n):
    lst=list(map(int,input().split()))
    graph[lst[0]]=lst[2:] i range(n) range n lst=list(map(int,input().split())) lst list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split graph[lst[0]]=lst[2:] graph[lst[0]] graph lst[0] lst 0 lst[2:] lst 2: 2 [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 seen=[[0,0] for _ in range(n+1)] seen [[0,0] for _ in range(n+1)] for i in range(1,n+1):
    if seen[i][0]==0:
        dfs(i) i range(1,n+1) range 1 n+1 n 1 if seen[i][0]==0:
        dfs(i) seen[i][0]==0 seen[i][0] [i] seen i 0 0 dfs(i) dfs i for i in range(1,n+1):
    print("{} {} {}".format(i,seen[i][0],seen[i][1])) i range(1,n+1) range 1 n+1 n 1 print("{} {} {}".format(i,seen[i][0],seen[i][1])) print "{} {} {}".format(i,seen[i][0],seen[i][1]) "{} {} {}".format "{} {} {}" format i seen[i][0] [i] seen i 0 seen[i][1] [i] seen i 1 lst=list(map(int,input().split())) list(map(int,input().split())) lst def dfs(i):
    global token
    token+=1
    seen[i][0]=token
    for x in graph[i]:
        if seen[x][0]==0:
            dfs(x)
    token+=1
    seen[i][1]=token def dfs(i):
    global token
    token+=1
    seen[i][0]=token
    for x in graph[i]:
        if seen[x][0]==0:
            dfs(x)
    token+=1
    seen[i][1]=token dfs token=0 0 token global graph n=int(input()) int(input()) n seen=[[0,0] for _ in range(n+1)] [[0,0] for _ in range(n+1)] seen global seen graph=[None for _ in range(n+1)] [None for _ in range(n+1)] graph
global graph
global seen
token=0

def dfs(i):
    global token
    token+=1
    seen[i][0]=token
    for x in graph[i]:
        if seen[x][0]==0:
            dfs(x)
    token+=1
    seen[i][1]=token


n=int(input())

graph=[None for _ in range(n+1)]

for i in range(n):
    lst=list(map(int,input().split()))
    graph[lst[0]]=lst[2:]

seen=[[0,0] for _ in range(n+1)]

for i in range(1,n+1):
    if seen[i][0]==0:
        dfs(i)

for i in range(1,n+1):
    print("{} {} {}".format(i,seen[i][0],seen[i][1]))
