N = int(input())

from collections import deque,defaultdict
G = defaultdict(deque)
for i in range(1,N+1):
    t = [int(i) for i in input().split(' ')]
    for j in range(t[1]):
        G[t[0]].append(t[j+2])

time = 1
arrive_time = [-1] * (N + 1) # 到着時刻
finish_time = [-1] * (N + 1) # 到着時刻

def dfs(G,s):
    global time
    stack = deque([s])
    arrive_time[s] = time
    while stack:
        t = stack[-1]
        if G[t]:
            w = G[t].popleft()
            if arrive_time[w] >= 0:
                continue
            elif w in stack:
                continue
            else:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[t] = time
            stack.pop()
            
    return arrive_time,finish_time

for i in range(1,N+1):
    if arrive_time[i] < 0:
        arrive,finish = dfs(G,i)
        time += 1

for i, (a, f) in enumerate(zip(arrive,finish)):
    if not i == 0:
        print(i,a,f) N = int(input()) N int(input()) int input() input from collections import deque,defaultdict G = defaultdict(deque) G defaultdict(deque) defaultdict deque for i in range(1,N+1):
    t = [int(i) for i in input().split(' ')]
    for j in range(t[1]):
        G[t[0]].append(t[j+2]) i range(1,N+1) range 1 N+1 N 1 int(i) for i in input().split(' ') for i in input().split(' ') i input().split(' ') ().split () input split ' ' for i in input().split(' ') int(i) int i t = [int(i) for i in input().split(' ')] t [int(i) for i in input().split(' ')] for j in range(t[1]):
        G[t[0]].append(t[j+2]) j range(t[1]) range t[1] t 1 G[t[0]].append(t[j+2]) [t[0]].append [t[0]] G t[0] t 0 append t[j+2] t j+2 j 2 time = 1 time 1 arrive_time = [-1] * (N + 1) arrive_time [-1] * (N + 1) [-1] -1 N + 1 N 1 finish_time = [-1] * (N + 1) finish_time [-1] * (N + 1) [-1] -1 N + 1 N 1 def dfs(G,s):
    global time
    stack = deque([s])
    arrive_time[s] = time
    while stack:
        t = stack[-1]
        if G[t]:
            w = G[t].popleft()
            if arrive_time[w] >= 0:
                continue
            elif w in stack:
                continue
            else:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[t] = time
            stack.pop()
            
    return arrive_time,finish_time dfs global time stack = deque([s]) stack deque([s]) deque [s] s arrive_time[s] = time arrive_time[s] arrive_time s time while stack:
        t = stack[-1]
        if G[t]:
            w = G[t].popleft()
            if arrive_time[w] >= 0:
                continue
            elif w in stack:
                continue
            else:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[t] = time
            stack.pop()
            
     stack t = stack[-1] t stack[-1] stack -1 if G[t]:
            w = G[t].popleft()
            if arrive_time[w] >= 0:
                continue
            elif w in stack:
                continue
            else:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[t] = time
            stack.pop()
            
     G[t] G t w = G[t].popleft() w G[t].popleft() [t].popleft [t] G t popleft if arrive_time[w] >= 0:
                continue
            elif w in stack:
                continue
            else:
                time += 1
                arrive_time[w] = time
                stack.append(w)
         arrive_time[w] >= 0 arrive_time[w] arrive_time w 0 continue elif w in stack:
                continue
             w in stack w stack continue time += 1 time 1 arrive_time[w] = time arrive_time[w] arrive_time w time stack.append(w) stack.append stack append w time += 1 time 1 finish_time[t] = time finish_time[t] finish_time t time stack.pop() stack.pop stack pop return arrive_time,finish_time return arrive_time,finish_time arrive_time finish_time G G s s for i in range(1,N+1):
    if arrive_time[i] < 0:
        arrive,finish = dfs(G,i)
        time += 1 i range(1,N+1) range 1 N+1 N 1 if arrive_time[i] < 0:
        arrive,finish = dfs(G,i)
        time += 1 arrive_time[i] < 0 arrive_time[i] arrive_time i 0 arrive,finish = dfs(G,i) arrive dfs(G,i) dfs G i finish time += 1 time 1 for i, (a, f) in enumerate(zip(arrive,finish)):
    if not i == 0:
        print(i,a,f) i (a, f) a f enumerate(zip(arrive,finish)) enumerate zip(arrive,finish) zip arrive finish if not i == 0:
        print(i,a,f) not i == 0 i == 0 i 0 print(i,a,f) print i a f t = [int(i) for i in input().split(' ')] [int(i) for i in input().split(' ')] t finish = dfs(G,i) dfs(G,i) finish def dfs(G,s):
    global time
    stack = deque([s])
    arrive_time[s] = time
    while stack:
        t = stack[-1]
        if G[t]:
            w = G[t].popleft()
            if arrive_time[w] >= 0:
                continue
            elif w in stack:
                continue
            else:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[t] = time
            stack.pop()
            
    return arrive_time,finish_time def dfs(G,s):
    global time
    stack = deque([s])
    arrive_time[s] = time
    while stack:
        t = stack[-1]
        if G[t]:
            w = G[t].popleft()
            if arrive_time[w] >= 0:
                continue
            elif w in stack:
                continue
            else:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[t] = time
            stack.pop()
            
    return arrive_time,finish_time dfs finish_time = [-1] * (N + 1) [-1] * (N + 1) finish_time arrive,finish = dfs(G,i) dfs(G,i) arrive N = int(input()) int(input()) N G = defaultdict(deque) defaultdict(deque) G arrive_time = [-1] * (N + 1) [-1] * (N + 1) arrive_time time += 1 1 time time = 1 1 time
N = int(input())

from collections import deque,defaultdict
G = defaultdict(deque)
for i in range(1,N+1):
    t = [int(i) for i in input().split(' ')]
    for j in range(t[1]):
        G[t[0]].append(t[j+2])

time = 1
arrive_time = [-1] * (N + 1) # 到着時刻
finish_time = [-1] * (N + 1) # 到着時刻

def dfs(G,s):
    global time
    stack = deque([s])
    arrive_time[s] = time
    while stack:
        t = stack[-1]
        if G[t]:
            w = G[t].popleft()
            if arrive_time[w] >= 0:
                continue
            elif w in stack:
                continue
            else:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[t] = time
            stack.pop()
            
    return arrive_time,finish_time

for i in range(1,N+1):
    if arrive_time[i] < 0:
        arrive,finish = dfs(G,i)
        time += 1

for i, (a, f) in enumerate(zip(arrive,finish)):
    if not i == 0:
        print(i,a,f)
