n = int(raw_input())

d = [0 for i in range(n)]
f = [0 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
st = [0 for i in range(n)]
t = [0]

def DFS_visit(s):
    st[s] = 1
    t[0] += 1
    d[s] = t[0]
    for e in range(n):
        if M[s][e] == 1 and st[e] == 0:
            DFS_visit(e)
    st[s] == 2
    t[0] += 1
    f[s] = t[0]

def DFS():
    for s in range(n):
        if st[s] == 0:
            DFS_visit(s)
    for s in range(n):
        print'{0} {1} {2}'.format(s+1, d[s], f[s])
    
for i in range(n):
    G = map(int, raw_input().split())
    for j in range(G[1]):
        M[G[0]-1][G[2+j]-1] = 1

DFS() n = int(raw_input()) n int(raw_input()) int raw_input() raw_input 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 d = [0 for i in range(n)] d [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 f = [0 for i in range(n)] f [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 G = [0 for i in range(n)] G [0 for i in range(n)] [0 for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [0 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] M [[0 for i in range(n)] for j in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 st = [0 for i in range(n)] st [0 for i in range(n)] t = [0] t [0] 0 def DFS_visit(s):
    st[s] = 1
    t[0] += 1
    d[s] = t[0]
    for e in range(n):
        if M[s][e] == 1 and st[e] == 0:
            DFS_visit(e)
    st[s] == 2
    t[0] += 1
    f[s] = t[0] DFS_visit st[s] = 1 st[s] st s 1 t[0] += 1 t[0] t 0 1 d[s] = t[0] d[s] d s t[0] t 0 for e in range(n):
        if M[s][e] == 1 and st[e] == 0:
            DFS_visit(e)
     e range(n) range n if M[s][e] == 1 and st[e] == 0:
            DFS_visit(e)
     M[s][e] == 1 and st[e] == 0 M[s][e] == 1 M[s][e] [s] M s e 1 st[e] == 0 st[e] st e 0 DFS_visit(e) DFS_visit e st[s] == 2 st[s] st s 2 t[0] += 1 t[0] t 0 1 f[s] = t[0] f[s] f s t[0] t 0 s s def DFS():
    for s in range(n):
        if st[s] == 0:
            DFS_visit(s)
    for s in range(n):
        print'{0} {1} {2}'.format(s+1, d[s], f[s])
     DFS for s in range(n):
        if st[s] == 0:
            DFS_visit(s)
     s range(n) range n if st[s] == 0:
            DFS_visit(s)
     st[s] == 0 st[s] st s 0 DFS_visit(s) DFS_visit s for s in range(n):
        print'{0} {1} {2}'.format(s+1, d[s], f[s])
     s range(n) range n print '{0} {1} {2}'.format(s+1, d[s], f[s]) '{0} {1} {2}'.format '{0} {1} {2}' format s+1 s 1 d[s] d s f[s] f s for i in range(n):
    G = map(int, raw_input().split())
    for j in range(G[1]):
        M[G[0]-1][G[2+j]-1] = 1 i range(n) range n G = map(int, raw_input().split()) G map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split for j in range(G[1]):
        M[G[0]-1][G[2+j]-1] = 1 j range(G[1]) range G[1] G 1 M[G[0]-1][G[2+j]-1] = 1 M[G[0]-1][G[2+j]-1] [G[0]-1] M G[0]-1 G[0] G 0 1 G[2+j]-1 G[2+j] G 2+j 2 j 1 1 DFS() DFS def DFS():
    for s in range(n):
        if st[s] == 0:
            DFS_visit(s)
    for s in range(n):
        print'{0} {1} {2}'.format(s+1, d[s], f[s])
     def DFS():
    for s in range(n):
        if st[s] == 0:
            DFS_visit(s)
    for s in range(n):
        print'{0} {1} {2}'.format(s+1, d[s], f[s])
     DFS G = map(int, raw_input().split()) map(int, raw_input().split()) G st = [0 for i in range(n)] [0 for i in range(n)] st G = [0 for i in range(n)] [0 for i in range(n)] G n = int(raw_input()) int(raw_input()) n d = [0 for i in range(n)] [0 for i in range(n)] d def DFS_visit(s):
    st[s] = 1
    t[0] += 1
    d[s] = t[0]
    for e in range(n):
        if M[s][e] == 1 and st[e] == 0:
            DFS_visit(e)
    st[s] == 2
    t[0] += 1
    f[s] = t[0] def DFS_visit(s):
    st[s] = 1
    t[0] += 1
    d[s] = t[0]
    for e in range(n):
        if M[s][e] == 1 and st[e] == 0:
            DFS_visit(e)
    st[s] == 2
    t[0] += 1
    f[s] = t[0] DFS_visit f = [0 for i in range(n)] [0 for i in range(n)] f M = [[0 for i in range(n)] for j in range(n)] [[0 for i in range(n)] for j in range(n)] M t = [0] [0] t
n = int(raw_input())

d = [0 for i in range(n)]
f = [0 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
st = [0 for i in range(n)]
t = [0]

def DFS_visit(s):
    st[s] = 1
    t[0] += 1
    d[s] = t[0]
    for e in range(n):
        if M[s][e] == 1 and st[e] == 0:
            DFS_visit(e)
    st[s] == 2
    t[0] += 1
    f[s] = t[0]

def DFS():
    for s in range(n):
        if st[s] == 0:
            DFS_visit(s)
    for s in range(n):
        print'{0} {1} {2}'.format(s+1, d[s], f[s])
    
for i in range(n):
    G = map(int, raw_input().split())
    for j in range(G[1]):
        M[G[0]-1][G[2+j]-1] = 1

DFS()