import sys
sys.setrecursionlimit(10**7)
time = 0
def input():
    return sys.stdin.readline()
n = int(input())
G = [[]]
d = [0]*(n+1)
f = [0]*(n+1)
for _ in range(n):
    G.append(list(map(int,input().split()))[2:])
def dfs(e):
    global time
    d[e] = time
    for nexte in G[e]:
        if d[nexte] == 0:
            time += 1
            dfs(nexte)
    time += 1
    f[e] = time

for i in range(1,n+1):
    if d[i] == 0:
        time += 1
        dfs(i)
for i in range(1,n+1):
    print(i,d[i],f[i])
 import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 time = 0 time 0 def input():
    return sys.stdin.readline() input return sys.stdin.readline() sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline n = int(input()) n int(input()) int input() input G = [[]] G [[]] [] d = [0]*(n+1) d [0]*(n+1) [0] 0 n+1 n 1 f = [0]*(n+1) f [0]*(n+1) [0] 0 n+1 n 1 for _ in range(n):
    G.append(list(map(int,input().split()))[2:]) _ range(n) range n G.append(list(map(int,input().split()))[2:]) G.append G append list(map(int,input().split()))[2:] (map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split 2: 2 def dfs(e):
    global time
    d[e] = time
    for nexte in G[e]:
        if d[nexte] == 0:
            time += 1
            dfs(nexte)
    time += 1
    f[e] = time dfs global time d[e] = time d[e] d e time for nexte in G[e]:
        if d[nexte] == 0:
            time += 1
            dfs(nexte)
     nexte G[e] G e if d[nexte] == 0:
            time += 1
            dfs(nexte)
     d[nexte] == 0 d[nexte] d nexte 0 time += 1 time 1 dfs(nexte) dfs nexte time += 1 time 1 f[e] = time f[e] f e time e e for i in range(1,n+1):
    if d[i] == 0:
        time += 1
        dfs(i) i range(1,n+1) range 1 n+1 n 1 if d[i] == 0:
        time += 1
        dfs(i) d[i] == 0 d[i] d i 0 time += 1 time 1 dfs(i) dfs i for i in range(1,n+1):
    print(i,d[i],f[i]) i range(1,n+1) range 1 n+1 n 1 print(i,d[i],f[i]) print i d[i] d i f[i] f i def input():
    return sys.stdin.readline() def input():
    return sys.stdin.readline() input G = [[]] [[]] G time = 0 0 time d = [0]*(n+1) [0]*(n+1) d f = [0]*(n+1) [0]*(n+1) f time += 1 1 time n = int(input()) int(input()) n def dfs(e):
    global time
    d[e] = time
    for nexte in G[e]:
        if d[nexte] == 0:
            time += 1
            dfs(nexte)
    time += 1
    f[e] = time def dfs(e):
    global time
    d[e] = time
    for nexte in G[e]:
        if d[nexte] == 0:
            time += 1
            dfs(nexte)
    time += 1
    f[e] = time dfs
import sys
sys.setrecursionlimit(10**7)
time = 0
def input():
    return sys.stdin.readline()
n = int(input())
G = [[]]
d = [0]*(n+1)
f = [0]*(n+1)
for _ in range(n):
    G.append(list(map(int,input().split()))[2:])
def dfs(e):
    global time
    d[e] = time
    for nexte in G[e]:
        if d[nexte] == 0:
            time += 1
            dfs(nexte)
    time += 1
    f[e] = time

for i in range(1,n+1):
    if d[i] == 0:
        time += 1
        dfs(i)
for i in range(1,n+1):
    print(i,d[i],f[i])

