def dfs(u):
    global dfs_color, d, f, t
    color[u] = GRAY
    d[u] += t
    t += 1
    for v in range(n):
        if (M[u][v] == 0):
            continue
        else:
            if (color[v] == WHITE):
               dfs(v)
    color[u] = BLACK
    f[u] = t
    t += 1

n = int(input())
M = [[False for i in range(n)] for j in range(n)]
for i in range(n):
    tmp = list(map(int, input().split()))
    for j in range(tmp[1]):
        M[tmp[0]-1][tmp[j+2]-1] = True

WHITE = 0
GRAY = 1
BLACK = 2
color = [WHITE for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
t = 1

for u in range(n):
    if (color[u] == WHITE):
        dfs(u)
for u in range(n):
    print(str(u+1), str(d[u]), str(f[u]), sep = " ") def dfs(u):
    global dfs_color, d, f, t
    color[u] = GRAY
    d[u] += t
    t += 1
    for v in range(n):
        if (M[u][v] == 0):
            continue
        else:
            if (color[v] == WHITE):
               dfs(v)
    color[u] = BLACK
    f[u] = t
    t += 1 dfs global dfs_color, d, f, t color[u] = GRAY color[u] color u GRAY d[u] += t d[u] d u t t += 1 t 1 for v in range(n):
        if (M[u][v] == 0):
            continue
        else:
            if (color[v] == WHITE):
               dfs(v)
     v range(n) range n if (M[u][v] == 0):
            continue
        else:
            if (color[v] == WHITE):
               dfs(v)
     M[u][v] == 0 M[u][v] [u] M u v 0 continue if (color[v] == WHITE):
               dfs(v)
     color[v] == WHITE color[v] color v WHITE dfs(v) dfs v color[u] = BLACK color[u] color u BLACK f[u] = t f[u] f u t t += 1 t 1 u u n = int(input()) n int(input()) int input() input [False 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) [False for i in range(n)] M = [[False for i in range(n)] for j in range(n)] M [[False for i in range(n)] for j in range(n)] for i in range(n):
    tmp = list(map(int, input().split()))
    for j in range(tmp[1]):
        M[tmp[0]-1][tmp[j+2]-1] = True 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 for j in range(tmp[1]):
        M[tmp[0]-1][tmp[j+2]-1] = True j range(tmp[1]) range tmp[1] tmp 1 M[tmp[0]-1][tmp[j+2]-1] = True M[tmp[0]-1][tmp[j+2]-1] [tmp[0]-1] M tmp[0]-1 tmp[0] tmp 0 1 tmp[j+2]-1 tmp[j+2] tmp j+2 j 2 1 True WHITE = 0 WHITE 0 GRAY = 1 GRAY 1 BLACK = 2 BLACK 2 WHITE for i in range(n) for i in range(n) i range(n) range n for i in range(n) WHITE color = [WHITE for i in range(n)] color [WHITE 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 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)] t = 1 t 1 for u in range(n):
    if (color[u] == WHITE):
        dfs(u) u range(n) range n if (color[u] == WHITE):
        dfs(u) color[u] == WHITE color[u] color u WHITE dfs(u) dfs u for u in range(n):
    print(str(u+1), str(d[u]), str(f[u]), sep = " ") u range(n) range n print(str(u+1), str(d[u]), str(f[u]), sep = " ") print str(u+1) str u+1 u 1 str(d[u]) str d[u] d u str(f[u]) str f[u] f u sep = " " sep " " def dfs(u):
    global dfs_color, d, f, t
    color[u] = GRAY
    d[u] += t
    t += 1
    for v in range(n):
        if (M[u][v] == 0):
            continue
        else:
            if (color[v] == WHITE):
               dfs(v)
    color[u] = BLACK
    f[u] = t
    t += 1 def dfs(u):
    global dfs_color, d, f, t
    color[u] = GRAY
    d[u] += t
    t += 1
    for v in range(n):
        if (M[u][v] == 0):
            continue
        else:
            if (color[v] == WHITE):
               dfs(v)
    color[u] = BLACK
    f[u] = t
    t += 1 dfs M = [[False for i in range(n)] for j in range(n)] [[False for i in range(n)] for j in range(n)] M n = int(input()) int(input()) n BLACK = 2 2 BLACK tmp = list(map(int, input().split())) list(map(int, input().split())) tmp GRAY = 1 1 GRAY d = [0 for i in range(n)] [0 for i in range(n)] d color = [WHITE for i in range(n)] [WHITE for i in range(n)] color t = 1 1 t f = [0 for i in range(n)] [0 for i in range(n)] f WHITE = 0 0 WHITE
def dfs(u):
    global dfs_color, d, f, t
    color[u] = GRAY
    d[u] += t
    t += 1
    for v in range(n):
        if (M[u][v] == 0):
            continue
        else:
            if (color[v] == WHITE):
               dfs(v)
    color[u] = BLACK
    f[u] = t
    t += 1

n = int(input())
M = [[False for i in range(n)] for j in range(n)]
for i in range(n):
    tmp = list(map(int, input().split()))
    for j in range(tmp[1]):
        M[tmp[0]-1][tmp[j+2]-1] = True

WHITE = 0
GRAY = 1
BLACK = 2
color = [WHITE for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
t = 1

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