n = int(input())
g = [[] for _ in range(n+1)] #1-index
for i in range(n):
    u, k, *v = map(int, input().split())
    for j in v:
        g[u].append(j)

#-------------------------------------------
def dfs(v): #未訪問の点vから潜っていく
    global time
    seen[v] = 1 #訪問済にする
    time += 1
    d[v] = time
    if g[v]:
        for next_v in g[v]:
            if seen[next_v] == 1: continue
            dfs(next_v) #再帰
    
    time += 1
    f[v] = time
    
#-------------------------------------------
seen = [0]*(n+1) #1-index
seen[0] = 1
seen[1] = 1 
d = [0]*(n+1)
f = [0]*(n+1)
time = 0

dfs(1) #深堀り

for i in range(1,n+1): #孤立点対応
    if seen[i] == 0:
        dfs(i)

for i in range(1,n+1):
    print(i, d[i], f[i])
 n = int(input()) n int(input()) int input() input [] for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [] g = [[] for _ in range(n+1)] g [[] for _ in range(n+1)] for i in range(n):
    u, k, *v = map(int, input().split())
    for j in v:
        g[u].append(j)

#------------------------------------------- i 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 j in v:
        g[u].append(j)

#------------------------------------------- j v g[u].append(j) [u].append [u] g u append j def dfs(v): #未訪問の点vから潜っていく
    global time
    seen[v] = 1 #訪問済にする
    time += 1
    d[v] = time
    if g[v]:
        for next_v in g[v]:
            if seen[next_v] == 1: continue
            dfs(next_v) #再帰
    
    time += 1
    f[v] = time
    
#------------------------------------------- dfs global time seen[v] = 1 seen[v] seen v 1 time += 1 time 1 d[v] = time d[v] d v time if g[v]:
        for next_v in g[v]:
            if seen[next_v] == 1: continue
            dfs(next_v) #再帰
    
     g[v] g v for next_v in g[v]:
            if seen[next_v] == 1: continue
            dfs(next_v) #再帰
    
     next_v g[v] g v if seen[next_v] == 1: continue
             seen[next_v] == 1 seen[next_v] seen next_v 1 dfs(next_v) dfs next_v time += 1 time 1 f[v] = time f[v] f v time v v seen = [0]*(n+1) seen [0]*(n+1) [0] 0 n+1 n 1 seen[0] = 1 seen[0] seen 0 1 seen[1] = 1 seen[1] seen 1 1 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 time = 0 time 0 dfs(1) dfs 1 for i in range(1,n+1): #孤立点対応
    if seen[i] == 0:
        dfs(i) i range(1,n+1) range 1 n+1 n 1 if seen[i] == 0:
        dfs(i) seen[i] == 0 seen[i] seen i 0 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 f = [0]*(n+1) [0]*(n+1) f n = int(input()) int(input()) n seen = [0]*(n+1) [0]*(n+1) seen time = 0 0 time k, *v = map(int, input().split()) map(int, input().split()) k def dfs(v): #未訪問の点vから潜っていく
    global time
    seen[v] = 1 #訪問済にする
    time += 1
    d[v] = time
    if g[v]:
        for next_v in g[v]:
            if seen[next_v] == 1: continue
            dfs(next_v) #再帰
    
    time += 1
    f[v] = time
    
#------------------------------------------- def dfs(v): #未訪問の点vから潜っていく
    global time
    seen[v] = 1 #訪問済にする
    time += 1
    d[v] = time
    if g[v]:
        for next_v in g[v]:
            if seen[next_v] == 1: continue
            dfs(next_v) #再帰
    
    time += 1
    f[v] = time
    
#------------------------------------------- dfs d = [0]*(n+1) [0]*(n+1) d u, k, *v = map(int, input().split()) map(int, input().split()) u g = [[] for _ in range(n+1)] [[] for _ in range(n+1)] g
n = int(input())
g = [[] for _ in range(n+1)] #1-index
for i in range(n):
    u, k, *v = map(int, input().split())
    for j in v:
        g[u].append(j)

#-------------------------------------------
def dfs(v): #未訪問の点vから潜っていく
    global time
    seen[v] = 1 #訪問済にする
    time += 1
    d[v] = time
    if g[v]:
        for next_v in g[v]:
            if seen[next_v] == 1: continue
            dfs(next_v) #再帰
    
    time += 1
    f[v] = time
    
#-------------------------------------------
seen = [0]*(n+1) #1-index
seen[0] = 1
seen[1] = 1 
d = [0]*(n+1)
f = [0]*(n+1)
time = 0

dfs(1) #深堀り

for i in range(1,n+1): #孤立点対応
    if seen[i] == 0:
        dfs(i)

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

