def dfs_recursive(u):
    global time
    color[u] = 'gray'
    arrive[u] = time
    time += 1
    for v in range(n):
        if adjMat[u][v] == 1 and color[v] == 'white':
            dfs_recursive(v)
    color[u] = 'black'
    finish[u] = time
    time += 1


n = int(input())

adjMat = [[0] * n for _ in range(n)]
color = ['white'] * n
arrive = [0] * n
finish = [0] * n
time = 1

for _ in range(n):
    adj = list(map(int, input().split()))
    i = adj[0]
    v = adj[2:]
    for j in v:
        adjMat[i - 1][j - 1] = 1

for root in range(n):
    if color[root] == 'white':
        dfs_recursive(root)


for i in range(n):
    out = ''
    out += '{} {} {}'.format(i + 1, arrive[i], finish[i])
    print(out) def dfs_recursive(u):
    global time
    color[u] = 'gray'
    arrive[u] = time
    time += 1
    for v in range(n):
        if adjMat[u][v] == 1 and color[v] == 'white':
            dfs_recursive(v)
    color[u] = 'black'
    finish[u] = time
    time += 1 dfs_recursive global time color[u] = 'gray' color[u] color u 'gray' arrive[u] = time arrive[u] arrive u time time += 1 time 1 for v in range(n):
        if adjMat[u][v] == 1 and color[v] == 'white':
            dfs_recursive(v)
     v range(n) range n if adjMat[u][v] == 1 and color[v] == 'white':
            dfs_recursive(v)
     adjMat[u][v] == 1 and color[v] == 'white' adjMat[u][v] == 1 adjMat[u][v] [u] adjMat u v 1 color[v] == 'white' color[v] color v 'white' dfs_recursive(v) dfs_recursive v color[u] = 'black' color[u] color u 'black' finish[u] = time finish[u] finish u time time += 1 time 1 u u 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 adjMat = [[0] * n for _ in range(n)] adjMat [[0] * n for _ in range(n)] color = ['white'] * n color ['white'] * n ['white'] 'white' n arrive = [0] * n arrive [0] * n [0] 0 n finish = [0] * n finish [0] * n [0] 0 n time = 1 time 1 for _ in range(n):
    adj = list(map(int, input().split()))
    i = adj[0]
    v = adj[2:]
    for j in v:
        adjMat[i - 1][j - 1] = 1 _ range(n) range n adj = list(map(int, input().split())) adj list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split i = adj[0] i adj[0] adj 0 v = adj[2:] v adj[2:] adj 2: 2 for j in v:
        adjMat[i - 1][j - 1] = 1 j v adjMat[i - 1][j - 1] = 1 adjMat[i - 1][j - 1] [i - 1] adjMat i - 1 i 1 j - 1 j 1 1 for root in range(n):
    if color[root] == 'white':
        dfs_recursive(root) root range(n) range n if color[root] == 'white':
        dfs_recursive(root) color[root] == 'white' color[root] color root 'white' dfs_recursive(root) dfs_recursive root for i in range(n):
    out = ''
    out += '{} {} {}'.format(i + 1, arrive[i], finish[i])
    print(out) i range(n) range n out = '' out '' out += '{} {} {}'.format(i + 1, arrive[i], finish[i]) out '{} {} {}'.format(i + 1, arrive[i], finish[i]) '{} {} {}'.format '{} {} {}' format i + 1 i 1 arrive[i] arrive i finish[i] finish i print(out) print out finish = [0] * n [0] * n finish def dfs_recursive(u):
    global time
    color[u] = 'gray'
    arrive[u] = time
    time += 1
    for v in range(n):
        if adjMat[u][v] == 1 and color[v] == 'white':
            dfs_recursive(v)
    color[u] = 'black'
    finish[u] = time
    time += 1 def dfs_recursive(u):
    global time
    color[u] = 'gray'
    arrive[u] = time
    time += 1
    for v in range(n):
        if adjMat[u][v] == 1 and color[v] == 'white':
            dfs_recursive(v)
    color[u] = 'black'
    finish[u] = time
    time += 1 dfs_recursive adjMat = [[0] * n for _ in range(n)] [[0] * n for _ in range(n)] adjMat arrive = [0] * n [0] * n arrive out = '' '' out v = adj[2:] adj[2:] v n = int(input()) int(input()) n time = 1 1 time adj = list(map(int, input().split())) list(map(int, input().split())) adj color = ['white'] * n ['white'] * n color i = adj[0] adj[0] i out += '{} {} {}'.format(i + 1, arrive[i], finish[i]) '{} {} {}'.format(i + 1, arrive[i], finish[i]) out
def dfs_recursive(u):
    global time
    color[u] = 'gray'
    arrive[u] = time
    time += 1
    for v in range(n):
        if adjMat[u][v] == 1 and color[v] == 'white':
            dfs_recursive(v)
    color[u] = 'black'
    finish[u] = time
    time += 1


n = int(input())

adjMat = [[0] * n for _ in range(n)]
color = ['white'] * n
arrive = [0] * n
finish = [0] * n
time = 1

for _ in range(n):
    adj = list(map(int, input().split()))
    i = adj[0]
    v = adj[2:]
    for j in v:
        adjMat[i - 1][j - 1] = 1

for root in range(n):
    if color[root] == 'white':
        dfs_recursive(root)


for i in range(n):
    out = ''
    out += '{} {} {}'.format(i + 1, arrive[i], finish[i])
    print(out)