n = int(input())
Adj = [[0]]
for _ in range(n):
    Adj.append(list(map(int, input().split()))[2:])

visited = [False]*(n+1)
s = [0]*(n+1)
f = [0]*(n+1)
time = 0

def dfs(i):
    global time
    time += 1
    s[i] = time
    visited[i] = True
    for j in Adj[i]:
        if not visited[j]:
            dfs(j)
    time += 1
    f[i] = time

while not all(visited[1:]):
    i = visited[1:].index(False) + 1
    dfs(i)

for i in range(1, n+1):
    print(i,s[i], f[i]) n = int(input()) n int(input()) int input() input Adj = [[0]] Adj [[0]] [0] 0 for _ in range(n):
    Adj.append(list(map(int, input().split()))[2:]) _ range(n) range n Adj.append(list(map(int, input().split()))[2:]) Adj.append Adj 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 visited = [False]*(n+1) visited [False]*(n+1) [False] False n+1 n 1 s = [0]*(n+1) s [0]*(n+1) [0] 0 n+1 n 1 f = [0]*(n+1) f [0]*(n+1) [0] 0 n+1 n 1 time = 0 time 0 def dfs(i):
    global time
    time += 1
    s[i] = time
    visited[i] = True
    for j in Adj[i]:
        if not visited[j]:
            dfs(j)
    time += 1
    f[i] = time dfs global time time += 1 time 1 s[i] = time s[i] s i time visited[i] = True visited[i] visited i True for j in Adj[i]:
        if not visited[j]:
            dfs(j)
     j Adj[i] Adj i if not visited[j]:
            dfs(j)
     not visited[j] visited[j] visited j dfs(j) dfs j time += 1 time 1 f[i] = time f[i] f i time i i while not all(visited[1:]):
    i = visited[1:].index(False) + 1
    dfs(i) not all(visited[1:]) all(visited[1:]) all visited[1:] visited 1: 1 i = visited[1:].index(False) + 1 i visited[1:].index(False) + 1 visited[1:].index(False) [1:].index [1:] visited 1: 1 index False 1 dfs(i) dfs i for i in range(1, n+1):
    print(i,s[i], f[i]) i range(1, n+1) range 1 n+1 n 1 print(i,s[i], f[i]) print i s[i] s i f[i] f i s = [0]*(n+1) [0]*(n+1) s time = 0 0 time visited = [False]*(n+1) [False]*(n+1) visited def dfs(i):
    global time
    time += 1
    s[i] = time
    visited[i] = True
    for j in Adj[i]:
        if not visited[j]:
            dfs(j)
    time += 1
    f[i] = time def dfs(i):
    global time
    time += 1
    s[i] = time
    visited[i] = True
    for j in Adj[i]:
        if not visited[j]:
            dfs(j)
    time += 1
    f[i] = time dfs i = visited[1:].index(False) + 1 visited[1:].index(False) + 1 i Adj = [[0]] [[0]] Adj n = int(input()) int(input()) n f = [0]*(n+1) [0]*(n+1) f
n = int(input())
Adj = [[0]]
for _ in range(n):
    Adj.append(list(map(int, input().split()))[2:])

visited = [False]*(n+1)
s = [0]*(n+1)
f = [0]*(n+1)
time = 0

def dfs(i):
    global time
    time += 1
    s[i] = time
    visited[i] = True
    for j in Adj[i]:
        if not visited[j]:
            dfs(j)
    time += 1
    f[i] = time

while not all(visited[1:]):
    i = visited[1:].index(False) + 1
    dfs(i)

for i in range(1, n+1):
    print(i,s[i], f[i])
