import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

global current_time
global visited,go_time,back_time
global G


def dfs(node_id):
    global current_time #書かないとローカル変数扱いされる
    go_time[node_id] = current_time
    current_time += 1

    for next_node in G[node_id]:

        if visited[next_node] == True:
            continue
        visited[next_node] = True
        dfs(next_node)

    back_time[node_id] = current_time
    current_time += 1


V = int(input())

G = [[] for i in range(V)]

visited = [False]*V

go_time = [0]*V
back_time = [0]*V

for loop in range(V):
    node_id,num,*tmp_adj = list(map(int,input().split()))
    node_id -= 1
    for i in range(num):
        G[node_id].append(tmp_adj[i]-1)

current_time = 1;

for i in range(V):
    if visited[i] == True:
        continue
    visited[i] = True
    dfs(i)

for i in range(V):
    print("%d %d %d"%(i+1,go_time[i],back_time[i]))




 import heapq heapq from collections import deque from enum import Enum import sys sys import math math from _heapq import heappush, heappop BIG_NUM = 2000000000 BIG_NUM 2000000000 MOD = 1000000007 MOD 1000000007 EPS = 0.000000001 EPS 0.000000001 global current_time global visited,go_time,back_time global G def dfs(node_id):
    global current_time #書かないとローカル変数扱いされる
    go_time[node_id] = current_time
    current_time += 1

    for next_node in G[node_id]:

        if visited[next_node] == True:
            continue
        visited[next_node] = True
        dfs(next_node)

    back_time[node_id] = current_time
    current_time += 1 dfs global current_time go_time[node_id] = current_time go_time[node_id] go_time node_id current_time current_time += 1 current_time 1 for next_node in G[node_id]:

        if visited[next_node] == True:
            continue
        visited[next_node] = True
        dfs(next_node)

     next_node G[node_id] G node_id if visited[next_node] == True:
            continue
         visited[next_node] == True visited[next_node] visited next_node True continue visited[next_node] = True visited[next_node] visited next_node True dfs(next_node) dfs next_node back_time[node_id] = current_time back_time[node_id] back_time node_id current_time current_time += 1 current_time 1 node_id node_id V = int(input()) V int(input()) int input() input [] for i in range(V) for i in range(V) i range(V) range V for i in range(V) [] G = [[] for i in range(V)] G [[] for i in range(V)] visited = [False]*V visited [False]*V [False] False V go_time = [0]*V go_time [0]*V [0] 0 V back_time = [0]*V back_time [0]*V [0] 0 V for loop in range(V):
    node_id,num,*tmp_adj = list(map(int,input().split()))
    node_id -= 1
    for i in range(num):
        G[node_id].append(tmp_adj[i]-1) loop range(V) range V node_id,num,*tmp_adj = list(map(int,input().split())) node_id list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split num *tmp_adj tmp_adj node_id -= 1 node_id 1 for i in range(num):
        G[node_id].append(tmp_adj[i]-1) i range(num) range num G[node_id].append(tmp_adj[i]-1) [node_id].append [node_id] G node_id append tmp_adj[i]-1 tmp_adj[i] tmp_adj i 1 current_time = 1 current_time 1 for i in range(V):
    if visited[i] == True:
        continue
    visited[i] = True
    dfs(i) i range(V) range V if visited[i] == True:
        continue
     visited[i] == True visited[i] visited i True continue visited[i] = True visited[i] visited i True dfs(i) dfs i for i in range(V):
    print("%d %d %d"%(i+1,go_time[i],back_time[i])) i range(V) range V print("%d %d %d"%(i+1,go_time[i],back_time[i])) print "%d %d %d"%(i+1,go_time[i],back_time[i]) "%d %d %d" (i+1,go_time[i],back_time[i]) i+1 i 1 go_time[i] go_time i back_time[i] back_time i global current_time current_time = 1 1 current_time node_id -= 1 1 node_id MOD = 1000000007 1000000007 MOD global G def dfs(node_id):
    global current_time #書かないとローカル変数扱いされる
    go_time[node_id] = current_time
    current_time += 1

    for next_node in G[node_id]:

        if visited[next_node] == True:
            continue
        visited[next_node] = True
        dfs(next_node)

    back_time[node_id] = current_time
    current_time += 1 def dfs(node_id):
    global current_time #書かないとローカル変数扱いされる
    go_time[node_id] = current_time
    current_time += 1

    for next_node in G[node_id]:

        if visited[next_node] == True:
            continue
        visited[next_node] = True
        dfs(next_node)

    back_time[node_id] = current_time
    current_time += 1 dfs num,*tmp_adj = list(map(int,input().split())) list(map(int,input().split())) num BIG_NUM = 2000000000 2000000000 BIG_NUM EPS = 0.000000001 0.000000001 EPS global visited,go_time,back_time go_time = [0]*V [0]*V go_time node_id,num,*tmp_adj = list(map(int,input().split())) list(map(int,input().split())) node_id V = int(input()) int(input()) V G = [[] for i in range(V)] [[] for i in range(V)] G visited = [False]*V [False]*V visited back_time = [0]*V [0]*V back_time
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

global current_time
global visited,go_time,back_time
global G


def dfs(node_id):
    global current_time #書かないとローカル変数扱いされる
    go_time[node_id] = current_time
    current_time += 1

    for next_node in G[node_id]:

        if visited[next_node] == True:
            continue
        visited[next_node] = True
        dfs(next_node)

    back_time[node_id] = current_time
    current_time += 1


V = int(input())

G = [[] for i in range(V)]

visited = [False]*V

go_time = [0]*V
back_time = [0]*V

for loop in range(V):
    node_id,num,*tmp_adj = list(map(int,input().split()))
    node_id -= 1
    for i in range(num):
        G[node_id].append(tmp_adj[i]-1)

current_time = 1;

for i in range(V):
    if visited[i] == True:
        continue
    visited[i] = True
    dfs(i)

for i in range(V):
    print("%d %d %d"%(i+1,go_time[i],back_time[i]))





