#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy
setrecursionlimit(10**6)

#@pysnooper.snoop()
def dfs(v,s):
    seen[v]=True
    first[v]=s
    s+=1
    #print(v,g[v])
    for i in g[v]:
        if seen[i]:
            continue
        s=dfs(i,s)
    #print(s)
    last[v]=s
    return s+1

n=int(stdin.readline().rstrip())
seen=[False]*n
first=[0]*n
last=[0]*n
g=[[] for _ in range(n)]
s=1
for i in range(n):
    v=list(map(int,stdin.readline().rstrip().split()))
    for j in v[2:]:
        g[v[0]-1].append(j-1)
for i in range(n):
    if not seen[i]:
        s=dfs(i,s)
for i in range(n):
    print(i+1,first[i],last[i]) from sys import stdin,setrecursionlimit setrecursionlimit(10**6) setrecursionlimit 10**6 10 6 def dfs(v,s):
    seen[v]=True
    first[v]=s
    s+=1
    #print(v,g[v])
    for i in g[v]:
        if seen[i]:
            continue
        s=dfs(i,s)
    #print(s)
    last[v]=s
    return s+1 dfs seen[v]=True seen[v] seen v True first[v]=s first[v] first v s s+=1 s 1 for i in g[v]:
        if seen[i]:
            continue
        s=dfs(i,s)
    #print(s)
     i g[v] g v if seen[i]:
            continue
         seen[i] seen i continue s=dfs(i,s) s dfs(i,s) dfs i s last[v]=s last[v] last v s return s+1 s+1 s 1 v v s s n=int(stdin.readline().rstrip()) n int(stdin.readline().rstrip()) int stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip seen=[False]*n seen [False]*n [False] False n first=[0]*n first [0]*n [0] 0 n last=[0]*n last [0]*n [0] 0 n [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] g=[[] for _ in range(n)] g [[] for _ in range(n)] s=1 s 1 for i in range(n):
    v=list(map(int,stdin.readline().rstrip().split()))
    for j in v[2:]:
        g[v[0]-1].append(j-1) i range(n) range n v=list(map(int,stdin.readline().rstrip().split())) v list(map(int,stdin.readline().rstrip().split())) list map(int,stdin.readline().rstrip().split()) map int stdin.readline().rstrip().split() stdin.readline().rstrip().split stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip split for j in v[2:]:
        g[v[0]-1].append(j-1) j v[2:] v 2: 2 g[v[0]-1].append(j-1) [v[0]-1].append [v[0]-1] g v[0]-1 v[0] v 0 1 append j-1 j 1 for i in range(n):
    if not seen[i]:
        s=dfs(i,s) i range(n) range n if not seen[i]:
        s=dfs(i,s) not seen[i] seen[i] seen i s=dfs(i,s) s dfs(i,s) dfs i s for i in range(n):
    print(i+1,first[i],last[i]) i range(n) range n print(i+1,first[i],last[i]) print i+1 i 1 first[i] first i last[i] last i def dfs(v,s):
    seen[v]=True
    first[v]=s
    s+=1
    #print(v,g[v])
    for i in g[v]:
        if seen[i]:
            continue
        s=dfs(i,s)
    #print(s)
    last[v]=s
    return s+1 def dfs(v,s):
    seen[v]=True
    first[v]=s
    s+=1
    #print(v,g[v])
    for i in g[v]:
        if seen[i]:
            continue
        s=dfs(i,s)
    #print(s)
    last[v]=s
    return s+1 dfs seen=[False]*n [False]*n seen n=int(stdin.readline().rstrip()) int(stdin.readline().rstrip()) n v=list(map(int,stdin.readline().rstrip().split())) list(map(int,stdin.readline().rstrip().split())) v last=[0]*n [0]*n last g=[[] for _ in range(n)] [[] for _ in range(n)] g s=1 1 s s=dfs(i,s) dfs(i,s) s first=[0]*n [0]*n first
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy
setrecursionlimit(10**6)

#@pysnooper.snoop()
def dfs(v,s):
    seen[v]=True
    first[v]=s
    s+=1
    #print(v,g[v])
    for i in g[v]:
        if seen[i]:
            continue
        s=dfs(i,s)
    #print(s)
    last[v]=s
    return s+1

n=int(stdin.readline().rstrip())
seen=[False]*n
first=[0]*n
last=[0]*n
g=[[] for _ in range(n)]
s=1
for i in range(n):
    v=list(map(int,stdin.readline().rstrip().split()))
    for j in v[2:]:
        g[v[0]-1].append(j-1)
for i in range(n):
    if not seen[i]:
        s=dfs(i,s)
for i in range(n):
    print(i+1,first[i],last[i])
