N = 100
WHITE = 0
GRAY = 1
BLACK = 2

d = [-1] * N
f = [-1] * N

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

def dfs(n):
    global d
    global f
    color = []
    for u in range(n):
        color.append(WHITE)
    tt = 0

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

n = int(input())

M = [[0] * n for _ in range(n)]

for i in range(n):
    I = list(map(int, input().split()))
    u = I[0] - 1
    k = I[1]
    for j in range(k):
        v = I[j+2] - 1
        M[u][v] = 1

#print(M)

dfs(n) N = 100 N 100 WHITE = 0 WHITE 0 GRAY = 1 GRAY 1 BLACK = 2 BLACK 2 d = [-1] * N d [-1] * N [-1] -1 N f = [-1] * N f [-1] * N [-1] -1 N def dfs_visit(n, u, tt, color):
    global d
    global f
    color[u] = GRAY
    tt += 1
    d[u] = tt
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            tt = dfs_visit(n, v, tt, color)
    color[u] = BLACK
    tt += 1
    f[u] = tt
    return tt dfs_visit global d global f color[u] = GRAY color[u] color u GRAY tt += 1 tt 1 d[u] = tt d[u] d u tt for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            tt = dfs_visit(n, v, tt, color)
     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:
            tt = dfs_visit(n, v, tt, color)
     color[v] == WHITE color[v] color v WHITE tt = dfs_visit(n, v, tt, color) tt dfs_visit(n, v, tt, color) dfs_visit n v tt color color[u] = BLACK color[u] color u BLACK tt += 1 tt 1 f[u] = tt f[u] f u tt return tt tt n n u u tt tt color color def dfs(n):
    global d
    global f
    color = []
    for u in range(n):
        color.append(WHITE)
    tt = 0

    for u in range(n):
        if color[u] == WHITE:
            tt = dfs_visit(n, u, tt, color)
    
    for u in range(n):
        print(u+1, d[u], f[u]) dfs global d global f color = [] color [] for u in range(n):
        color.append(WHITE)
     u range(n) range n color.append(WHITE) color.append color append WHITE tt = 0 tt 0 for u in range(n):
        if color[u] == WHITE:
            tt = dfs_visit(n, u, tt, color)
    
     u range(n) range n if color[u] == WHITE:
            tt = dfs_visit(n, u, tt, color)
    
     color[u] == WHITE color[u] color u WHITE tt = dfs_visit(n, u, tt, color) tt dfs_visit(n, u, tt, color) dfs_visit n u tt color for u in range(n):
        print(u+1, d[u], f[u]) u range(n) range n print(u+1, d[u], f[u]) print u+1 u 1 d[u] d u f[u] f u n n n = int(input()) n int(input()) int input() input [0] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0] * n [0] 0 n M = [[0] * n for _ in range(n)] M [[0] * n for _ in range(n)] for i in range(n):
    I = list(map(int, input().split()))
    u = I[0] - 1
    k = I[1]
    for j in range(k):
        v = I[j+2] - 1
        M[u][v] = 1

#print(M) i range(n) range n I = list(map(int, input().split())) I list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split u = I[0] - 1 u I[0] - 1 I[0] I 0 1 k = I[1] k I[1] I 1 for j in range(k):
        v = I[j+2] - 1
        M[u][v] = 1

#print(M) j range(k) range k v = I[j+2] - 1 v I[j+2] - 1 I[j+2] I j+2 j 2 1 M[u][v] = 1 M[u][v] [u] M u v 1 dfs(n) dfs n GRAY = 1 1 GRAY def dfs_visit(n, u, tt, color):
    global d
    global f
    color[u] = GRAY
    tt += 1
    d[u] = tt
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            tt = dfs_visit(n, v, tt, color)
    color[u] = BLACK
    tt += 1
    f[u] = tt
    return tt def dfs_visit(n, u, tt, color):
    global d
    global f
    color[u] = GRAY
    tt += 1
    d[u] = tt
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            tt = dfs_visit(n, v, tt, color)
    color[u] = BLACK
    tt += 1
    f[u] = tt
    return tt dfs_visit I = list(map(int, input().split())) list(map(int, input().split())) I def dfs(n):
    global d
    global f
    color = []
    for u in range(n):
        color.append(WHITE)
    tt = 0

    for u in range(n):
        if color[u] == WHITE:
            tt = dfs_visit(n, u, tt, color)
    
    for u in range(n):
        print(u+1, d[u], f[u]) def dfs(n):
    global d
    global f
    color = []
    for u in range(n):
        color.append(WHITE)
    tt = 0

    for u in range(n):
        if color[u] == WHITE:
            tt = dfs_visit(n, u, tt, color)
    
    for u in range(n):
        print(u+1, d[u], f[u]) dfs WHITE = 0 0 WHITE n = int(input()) int(input()) n BLACK = 2 2 BLACK N = 100 100 N d = [-1] * N [-1] * N d v = I[j+2] - 1 I[j+2] - 1 v f = [-1] * N [-1] * N f u = I[0] - 1 I[0] - 1 u k = I[1] I[1] k M = [[0] * n for _ in range(n)] [[0] * n for _ in range(n)] M
N = 100
WHITE = 0
GRAY = 1
BLACK = 2

d = [-1] * N
f = [-1] * N

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

def dfs(n):
    global d
    global f
    color = []
    for u in range(n):
        color.append(WHITE)
    tt = 0

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

n = int(input())

M = [[0] * n for _ in range(n)]

for i in range(n):
    I = list(map(int, input().split()))
    u = I[0] - 1
    k = I[1]
    for j in range(k):
        v = I[j+2] - 1
        M[u][v] = 1

#print(M)

dfs(n)
