stack=[]
n=int(input())
color=[]
graph={}
d_time=[]
f_time=[]
time=0
root=[i for i in range(1,n+1)]

for i in range(n):
    tmp=list(map(int,input().split()))
    graph[tmp[0]]=[0 for j in range(n+1)]
    color=["white" for l in range(n+1)]
    d_time=[0 for j in range(n+1)]
    f_time=[0 for j in range(n+1)]
    for k in range(tmp[1]):
        graph[tmp[0]][tmp[2+k]]=1
        if tmp[2+k] in root:
            root.remove(tmp[2+k])

def function(number):
    global time
    stack.append(number)
    color[number]="gray"
    time+=1
    d_time[number]=time
    while stack!=[]:
        u=stack[-1]
        if 1 in graph[u]:
            v=graph[u].index(1)
            graph[u][v]=0
            if color[v]=="white":
                color[v]="gray"
                time+=1
                d_time[v]=time
                stack.append(v)
        else:
            stack.pop()
            color[u]="black"
            time+=1
            f_time[u]=time

if root==[]:
    function(1)
else:
    for i in range(len(root)):
        function(root[i])

for i in range(1,n+1):
    print(i,d_time[i],f_time[i]) stack=[] stack [] n=int(input()) n int(input()) int input() input color=[] color [] graph={} graph {} d_time=[] d_time [] f_time=[] f_time [] time=0 time 0 i for i in range(1,n+1) for i in range(1,n+1) i range(1,n+1) range 1 n+1 n 1 for i in range(1,n+1) i root=[i for i in range(1,n+1)] root [i for i in range(1,n+1)] for i in range(n):
    tmp=list(map(int,input().split()))
    graph[tmp[0]]=[0 for j in range(n+1)]
    color=["white" for l in range(n+1)]
    d_time=[0 for j in range(n+1)]
    f_time=[0 for j in range(n+1)]
    for k in range(tmp[1]):
        graph[tmp[0]][tmp[2+k]]=1
        if tmp[2+k] in root:
            root.remove(tmp[2+k]) i range(n) range n tmp=list(map(int,input().split())) tmp list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split 0 for j in range(n+1) for j in range(n+1) j range(n+1) range n+1 n 1 for j in range(n+1) 0 graph[tmp[0]]=[0 for j in range(n+1)] graph[tmp[0]] graph tmp[0] tmp 0 [0 for j in range(n+1)] "white" for l in range(n+1) for l in range(n+1) l range(n+1) range n+1 n 1 for l in range(n+1) "white" color=["white" for l in range(n+1)] color ["white" for l in range(n+1)] 0 for j in range(n+1) for j in range(n+1) j range(n+1) range n+1 n 1 for j in range(n+1) 0 d_time=[0 for j in range(n+1)] d_time [0 for j in range(n+1)] 0 for j in range(n+1) for j in range(n+1) j range(n+1) range n+1 n 1 for j in range(n+1) 0 f_time=[0 for j in range(n+1)] f_time [0 for j in range(n+1)] for k in range(tmp[1]):
        graph[tmp[0]][tmp[2+k]]=1
        if tmp[2+k] in root:
            root.remove(tmp[2+k]) k range(tmp[1]) range tmp[1] tmp 1 graph[tmp[0]][tmp[2+k]]=1 graph[tmp[0]][tmp[2+k]] [tmp[0]] graph tmp[0] tmp 0 tmp[2+k] tmp 2+k 2 k 1 if tmp[2+k] in root:
            root.remove(tmp[2+k]) tmp[2+k] in root tmp[2+k] tmp 2+k 2 k root root.remove(tmp[2+k]) root.remove root remove tmp[2+k] tmp 2+k 2 k def function(number):
    global time
    stack.append(number)
    color[number]="gray"
    time+=1
    d_time[number]=time
    while stack!=[]:
        u=stack[-1]
        if 1 in graph[u]:
            v=graph[u].index(1)
            graph[u][v]=0
            if color[v]=="white":
                color[v]="gray"
                time+=1
                d_time[v]=time
                stack.append(v)
        else:
            stack.pop()
            color[u]="black"
            time+=1
            f_time[u]=time function global time stack.append(number) stack.append stack append number color[number]="gray" color[number] color number "gray" time+=1 time 1 d_time[number]=time d_time[number] d_time number time while stack!=[]:
        u=stack[-1]
        if 1 in graph[u]:
            v=graph[u].index(1)
            graph[u][v]=0
            if color[v]=="white":
                color[v]="gray"
                time+=1
                d_time[v]=time
                stack.append(v)
        else:
            stack.pop()
            color[u]="black"
            time+=1
            f_time[u]=time stack!=[] stack [] u=stack[-1] u stack[-1] stack -1 if 1 in graph[u]:
            v=graph[u].index(1)
            graph[u][v]=0
            if color[v]=="white":
                color[v]="gray"
                time+=1
                d_time[v]=time
                stack.append(v)
        else:
            stack.pop()
            color[u]="black"
            time+=1
            f_time[u]=time 1 in graph[u] 1 graph[u] graph u v=graph[u].index(1) v graph[u].index(1) [u].index [u] graph u index 1 graph[u][v]=0 graph[u][v] [u] graph u v 0 if color[v]=="white":
                color[v]="gray"
                time+=1
                d_time[v]=time
                stack.append(v)
         color[v]=="white" color[v] color v "white" color[v]="gray" color[v] color v "gray" time+=1 time 1 d_time[v]=time d_time[v] d_time v time stack.append(v) stack.append stack append v stack.pop() stack.pop stack pop color[u]="black" color[u] color u "black" time+=1 time 1 f_time[u]=time f_time[u] f_time u time number number if root==[]:
    function(1)
else:
    for i in range(len(root)):
        function(root[i]) root==[] root [] function(1) function 1 for i in range(len(root)):
        function(root[i]) i range(len(root)) range len(root) len root function(root[i]) function root[i] root i for i in range(1,n+1):
    print(i,d_time[i],f_time[i]) i range(1,n+1) range 1 n+1 n 1 print(i,d_time[i],f_time[i]) print i d_time[i] d_time i f_time[i] f_time i f_time=[] [] f_time color=[] [] color graph={} {} graph f_time=[0 for j in range(n+1)] [0 for j in range(n+1)] f_time root=[i for i in range(1,n+1)] [i for i in range(1,n+1)] root time=0 0 time color=["white" for l in range(n+1)] ["white" for l in range(n+1)] color def function(number):
    global time
    stack.append(number)
    color[number]="gray"
    time+=1
    d_time[number]=time
    while stack!=[]:
        u=stack[-1]
        if 1 in graph[u]:
            v=graph[u].index(1)
            graph[u][v]=0
            if color[v]=="white":
                color[v]="gray"
                time+=1
                d_time[v]=time
                stack.append(v)
        else:
            stack.pop()
            color[u]="black"
            time+=1
            f_time[u]=time def function(number):
    global time
    stack.append(number)
    color[number]="gray"
    time+=1
    d_time[number]=time
    while stack!=[]:
        u=stack[-1]
        if 1 in graph[u]:
            v=graph[u].index(1)
            graph[u][v]=0
            if color[v]=="white":
                color[v]="gray"
                time+=1
                d_time[v]=time
                stack.append(v)
        else:
            stack.pop()
            color[u]="black"
            time+=1
            f_time[u]=time function n=int(input()) int(input()) n stack=[] [] stack d_time=[] [] d_time tmp=list(map(int,input().split())) list(map(int,input().split())) tmp d_time=[0 for j in range(n+1)] [0 for j in range(n+1)] d_time
stack=[]
n=int(input())
color=[]
graph={}
d_time=[]
f_time=[]
time=0
root=[i for i in range(1,n+1)]

for i in range(n):
    tmp=list(map(int,input().split()))
    graph[tmp[0]]=[0 for j in range(n+1)]
    color=["white" for l in range(n+1)]
    d_time=[0 for j in range(n+1)]
    f_time=[0 for j in range(n+1)]
    for k in range(tmp[1]):
        graph[tmp[0]][tmp[2+k]]=1
        if tmp[2+k] in root:
            root.remove(tmp[2+k])

def function(number):
    global time
    stack.append(number)
    color[number]="gray"
    time+=1
    d_time[number]=time
    while stack!=[]:
        u=stack[-1]
        if 1 in graph[u]:
            v=graph[u].index(1)
            graph[u][v]=0
            if color[v]=="white":
                color[v]="gray"
                time+=1
                d_time[v]=time
                stack.append(v)
        else:
            stack.pop()
            color[u]="black"
            time+=1
            f_time[u]=time

if root==[]:
    function(1)
else:
    for i in range(len(root)):
        function(root[i])

for i in range(1,n+1):
    print(i,d_time[i],f_time[i])
