n = 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)]
color = [0 for i in range(n)]
tt    = [0]
WHITE = 0
GRAY  = 1
BLACK = 2

def dfs_visit(u):
    color[u] = GRAY
    tt[0] = tt[0] + 1
    d[u] = tt[0]
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(v)
    color[u] == BLACK
    tt[0] = tt[0] + 1
    f[u] = tt[0]

def dfs():
    for u in range(n):
        if color[u] == WHITE:
            dfs_visit(u)
    for u in range(n):
        print "%d %d %d" %(u + 1, d[u], f[u])

### MAIN
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 = input() n input() 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 color = [0 for i in range(n)] color [0 for i in range(n)] tt    = [0] tt [0] 0 WHITE = 0 WHITE 0 GRAY  = 1 GRAY 1 BLACK = 2 BLACK 2 def dfs_visit(u):
    color[u] = GRAY
    tt[0] = tt[0] + 1
    d[u] = tt[0]
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(v)
    color[u] == BLACK
    tt[0] = tt[0] + 1
    f[u] = tt[0] dfs_visit color[u] = GRAY color[u] color u GRAY tt[0] = tt[0] + 1 tt[0] tt 0 tt[0] + 1 tt[0] tt 0 1 d[u] = tt[0] d[u] d u tt[0] tt 0 for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(v)
     v range(n) range n if M[u][v] == 0:
            continue
         M[u][v] == 0 M[u][v] [u] M u v 0 continue if color[v] == WHITE:
            dfs_visit(v)
     color[v] == WHITE color[v] color v WHITE dfs_visit(v) dfs_visit v color[u] == BLACK color[u] color u BLACK tt[0] = tt[0] + 1 tt[0] tt 0 tt[0] + 1 tt[0] tt 0 1 f[u] = tt[0] f[u] f u tt[0] tt 0 u u def dfs():
    for u in range(n):
        if color[u] == WHITE:
            dfs_visit(u)
    for u in range(n):
        print "%d %d %d" %(u + 1, d[u], f[u])

### MAIN dfs for u in range(n):
        if color[u] == WHITE:
            dfs_visit(u)
     u range(n) range n if color[u] == WHITE:
            dfs_visit(u)
     color[u] == WHITE color[u] color u WHITE dfs_visit(u) dfs_visit u for u in range(n):
        print "%d %d %d" %(u + 1, d[u], f[u])

### MAIN u range(n) range n print "%d %d %d" %(u + 1, d[u], f[u]) "%d %d %d" (u + 1, d[u], f[u]) u + 1 u 1 d[u] d u f[u] f u 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 G     = [0 for i in range(n)] [0 for i in range(n)] G G = map(int, raw_input().split()) map(int, raw_input().split()) G def dfs():
    for u in range(n):
        if color[u] == WHITE:
            dfs_visit(u)
    for u in range(n):
        print "%d %d %d" %(u + 1, d[u], f[u])

### MAIN def dfs():
    for u in range(n):
        if color[u] == WHITE:
            dfs_visit(u)
    for u in range(n):
        print "%d %d %d" %(u + 1, d[u], f[u])

### MAIN dfs BLACK = 2 2 BLACK f     = [0 for i in range(n)] [0 for i in range(n)] f def dfs_visit(u):
    color[u] = GRAY
    tt[0] = tt[0] + 1
    d[u] = tt[0]
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(v)
    color[u] == BLACK
    tt[0] = tt[0] + 1
    f[u] = tt[0] def dfs_visit(u):
    color[u] = GRAY
    tt[0] = tt[0] + 1
    d[u] = tt[0]
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(v)
    color[u] == BLACK
    tt[0] = tt[0] + 1
    f[u] = tt[0] dfs_visit n = input() input() n d     = [0 for i in range(n)] [0 for i in range(n)] d GRAY  = 1 1 GRAY WHITE = 0 0 WHITE M     = [[0 for i in range(n)] for j in range(n)] [[0 for i in range(n)] for j in range(n)] M color = [0 for i in range(n)] [0 for i in range(n)] color tt    = [0] [0] tt
n = 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)]
color = [0 for i in range(n)]
tt    = [0]
WHITE = 0
GRAY  = 1
BLACK = 2

def dfs_visit(u):
    color[u] = GRAY
    tt[0] = tt[0] + 1
    d[u] = tt[0]
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(v)
    color[u] == BLACK
    tt[0] = tt[0] + 1
    f[u] = tt[0]

def dfs():
    for u in range(n):
        if color[u] == WHITE:
            dfs_visit(u)
    for u in range(n):
        print "%d %d %d" %(u + 1, d[u], f[u])

### MAIN
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()