def d(r):
    global n
    if t[r]:return
    n+=1
    t[r]=[r+1,n]
    for i in c[r]:d(i-1)
    n+=1
    t[r][2:]=[n]
m=input()
c=[0]*m
for _ in range(m):
    l=map(int,raw_input().split())
    c[l[0]-1]=l[2:]
n=0
t=[0]*m
for i in range(m):
    d(i)
    print " ".join(map(str,t[i])) def d(r):
    global n
    if t[r]:return
    n+=1
    t[r]=[r+1,n]
    for i in c[r]:d(i-1)
    n+=1
    t[r][2:]=[n] d global n if t[r]:return
     t[r] t r n+=1 n 1 t[r]=[r+1,n] t[r] t r [r+1,n] r+1 r 1 n for i in c[r]:d(i-1)
     i c[r] c r n+=1 n 1 t[r][2:]=[n] t[r][2:] [r] t r 2: 2 [n] n r r m=input() m input() input c=[0]*m c [0]*m [0] 0 m for _ in range(m):
    l=map(int,raw_input().split())
    c[l[0]-1]=l[2:] _ range(m) range m l=map(int,raw_input().split()) l map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split c[l[0]-1]=l[2:] c[l[0]-1] c l[0]-1 l[0] l 0 1 l[2:] l 2: 2 n=0 n 0 t=[0]*m t [0]*m [0] 0 m for i in range(m):
    d(i)
    print " ".join(map(str,t[i])) i range(m) range m d(i) d i print " ".join(map(str,t[i])) " ".join " " join map(str,t[i]) map str t[i] t i l=map(int,raw_input().split()) map(int,raw_input().split()) l def d(r):
    global n
    if t[r]:return
    n+=1
    t[r]=[r+1,n]
    for i in c[r]:d(i-1)
    n+=1
    t[r][2:]=[n] def d(r):
    global n
    if t[r]:return
    n+=1
    t[r]=[r+1,n]
    for i in c[r]:d(i-1)
    n+=1
    t[r][2:]=[n] d m=input() input() m c=[0]*m [0]*m c t=[0]*m [0]*m t n=0 0 n
def d(r):
    global n
    if t[r]:return
    n+=1
    t[r]=[r+1,n]
    for i in c[r]:d(i-1)
    n+=1
    t[r][2:]=[n]
m=input()
c=[0]*m
for _ in range(m):
    l=map(int,raw_input().split())
    c[l[0]-1]=l[2:]
n=0
t=[0]*m
for i in range(m):
    d(i)
    print " ".join(map(str,t[i]))