def dfs():
    tt = 0
    for u in range(N):
        if colors[u] == WHITE:
            tt = dfs_visit(u, tt)

def dfs_visit(u, tt):
    tt += 1
    colors[u] = GLAY
    d[u] = tt
    for v in range(N):
        if adjacency_list[u][v] == 1 and colors[v] == WHITE:
            tt = dfs_visit(v, tt)
    tt += 1
    colors[u] = BLACK
    f[u] = tt
    return tt


N = int(input())
adjacency_list = [[0 for j in range(N)] for i in range(N)]
for _ in range(N):
    u, k, *v = map(int, input().split())
    for i in v:
        adjacency_list[u-1][i-1] = 1

WHITE = 0
GLAY = 1
BLACK = 2
colors = [WHITE for _ in range(N)]
d = [0 for _ in range(N)]
f = [0 for _ in range(N)]

dfs()

for i in range(N):
    print("{} {} {}".format(i+1, d[i], f[i])) def dfs():
    tt = 0
    for u in range(N):
        if colors[u] == WHITE:
            tt = dfs_visit(u, tt) dfs tt = 0 tt 0 for u in range(N):
        if colors[u] == WHITE:
            tt = dfs_visit(u, tt) u range(N) range N if colors[u] == WHITE:
            tt = dfs_visit(u, tt) colors[u] == WHITE colors[u] colors u WHITE tt = dfs_visit(u, tt) tt dfs_visit(u, tt) dfs_visit u tt def dfs_visit(u, tt):
    tt += 1
    colors[u] = GLAY
    d[u] = tt
    for v in range(N):
        if adjacency_list[u][v] == 1 and colors[v] == WHITE:
            tt = dfs_visit(v, tt)
    tt += 1
    colors[u] = BLACK
    f[u] = tt
    return tt dfs_visit tt += 1 tt 1 colors[u] = GLAY colors[u] colors u GLAY d[u] = tt d[u] d u tt for v in range(N):
        if adjacency_list[u][v] == 1 and colors[v] == WHITE:
            tt = dfs_visit(v, tt)
     v range(N) range N if adjacency_list[u][v] == 1 and colors[v] == WHITE:
            tt = dfs_visit(v, tt)
     adjacency_list[u][v] == 1 and colors[v] == WHITE adjacency_list[u][v] == 1 adjacency_list[u][v] [u] adjacency_list u v 1 colors[v] == WHITE colors[v] colors v WHITE tt = dfs_visit(v, tt) tt dfs_visit(v, tt) dfs_visit v tt tt += 1 tt 1 colors[u] = BLACK colors[u] colors u BLACK f[u] = tt f[u] f u tt return tt tt u u tt tt N = int(input()) N int(input()) int input() input [0 for j in range(N)] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [0 for j in range(N)] adjacency_list = [[0 for j in range(N)] for i in range(N)] adjacency_list [[0 for j in range(N)] for i in range(N)] for _ in range(N):
    u, k, *v = map(int, input().split())
    for i in v:
        adjacency_list[u-1][i-1] = 1 _ range(N) range N u, k, *v = map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split k *v v for i in v:
        adjacency_list[u-1][i-1] = 1 i v adjacency_list[u-1][i-1] = 1 adjacency_list[u-1][i-1] [u-1] adjacency_list u-1 u 1 i-1 i 1 1 WHITE = 0 WHITE 0 GLAY = 1 GLAY 1 BLACK = 2 BLACK 2 WHITE for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) WHITE colors = [WHITE for _ in range(N)] colors [WHITE for _ in range(N)] 0 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) 0 d = [0 for _ in range(N)] d [0 for _ in range(N)] 0 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) 0 f = [0 for _ in range(N)] f [0 for _ in range(N)] dfs() dfs for i in range(N):
    print("{} {} {}".format(i+1, d[i], f[i])) i range(N) range N print("{} {} {}".format(i+1, d[i], f[i])) print "{} {} {}".format(i+1, d[i], f[i]) "{} {} {}".format "{} {} {}" format i+1 i 1 d[i] d i f[i] f i adjacency_list = [[0 for j in range(N)] for i in range(N)] [[0 for j in range(N)] for i in range(N)] adjacency_list f = [0 for _ in range(N)] [0 for _ in range(N)] f WHITE = 0 0 WHITE colors = [WHITE for _ in range(N)] [WHITE for _ in range(N)] colors d = [0 for _ in range(N)] [0 for _ in range(N)] d def dfs_visit(u, tt):
    tt += 1
    colors[u] = GLAY
    d[u] = tt
    for v in range(N):
        if adjacency_list[u][v] == 1 and colors[v] == WHITE:
            tt = dfs_visit(v, tt)
    tt += 1
    colors[u] = BLACK
    f[u] = tt
    return tt def dfs_visit(u, tt):
    tt += 1
    colors[u] = GLAY
    d[u] = tt
    for v in range(N):
        if adjacency_list[u][v] == 1 and colors[v] == WHITE:
            tt = dfs_visit(v, tt)
    tt += 1
    colors[u] = BLACK
    f[u] = tt
    return tt dfs_visit BLACK = 2 2 BLACK def dfs():
    tt = 0
    for u in range(N):
        if colors[u] == WHITE:
            tt = dfs_visit(u, tt) def dfs():
    tt = 0
    for u in range(N):
        if colors[u] == WHITE:
            tt = dfs_visit(u, tt) dfs GLAY = 1 1 GLAY N = int(input()) int(input()) N u, k, *v = map(int, input().split()) map(int, input().split()) u k, *v = map(int, input().split()) map(int, input().split()) k
def dfs():
    tt = 0
    for u in range(N):
        if colors[u] == WHITE:
            tt = dfs_visit(u, tt)

def dfs_visit(u, tt):
    tt += 1
    colors[u] = GLAY
    d[u] = tt
    for v in range(N):
        if adjacency_list[u][v] == 1 and colors[v] == WHITE:
            tt = dfs_visit(v, tt)
    tt += 1
    colors[u] = BLACK
    f[u] = tt
    return tt


N = int(input())
adjacency_list = [[0 for j in range(N)] for i in range(N)]
for _ in range(N):
    u, k, *v = map(int, input().split())
    for i in v:
        adjacency_list[u-1][i-1] = 1

WHITE = 0
GLAY = 1
BLACK = 2
colors = [WHITE for _ in range(N)]
d = [0 for _ in range(N)]
f = [0 for _ in range(N)]

dfs()

for i in range(N):
    print("{} {} {}".format(i+1, d[i], f[i]))
