N = int(input())
DG = {}
node_ls = []
is_visited = {}
#有効グラフをdictで管理することにする
for _ in range(N):
    tmp = input().split()
    node_id = tmp[0]
    node_ls.append(node_id)
    is_visited[node_id] = False
    adj_num = int(tmp[1])#各頂点の次元が入っている
    if adj_num != 0:
        DG[node_id] = tmp[2:]
    else:
        DG[node_id] = []


d = {}#最初に発見したときの時刻を記録
f = {}#隣接リストを調べ終えたときの完了時刻を記録
t = 1

def dfs(node):
    global t
    #終了条件
    if is_visited[node]:
        return

    is_visited[node] = True
    d[node] = t
    t += 1
    for no in DG[node]:
        dfs(no)
    f[node] = t
    t += 1

for node in node_ls:
    dfs(node)

#print(d,f)
for node in node_ls:
    print(node, d[node], f[node])
 N = int(input()) N int(input()) int input() input DG = {} DG {} node_ls = [] node_ls [] is_visited = {} is_visited {} for _ in range(N):
    tmp = input().split()
    node_id = tmp[0]
    node_ls.append(node_id)
    is_visited[node_id] = False
    adj_num = int(tmp[1])#各頂点の次元が入っている
    if adj_num != 0:
        DG[node_id] = tmp[2:]
    else:
        DG[node_id] = [] _ range(N) range N tmp = input().split() tmp input().split() ().split () input split node_id = tmp[0] node_id tmp[0] tmp 0 node_ls.append(node_id) node_ls.append node_ls append node_id is_visited[node_id] = False is_visited[node_id] is_visited node_id False adj_num = int(tmp[1]) adj_num int(tmp[1]) int tmp[1] tmp 1 if adj_num != 0:
        DG[node_id] = tmp[2:]
    else:
        DG[node_id] = [] adj_num != 0 adj_num 0 DG[node_id] = tmp[2:] DG[node_id] DG node_id tmp[2:] tmp 2: 2 DG[node_id] = [] DG[node_id] DG node_id [] d = {} d {} f = {} f {} t = 1 t 1 def dfs(node):
    global t
    #終了条件
    if is_visited[node]:
        return

    is_visited[node] = True
    d[node] = t
    t += 1
    for no in DG[node]:
        dfs(no)
    f[node] = t
    t += 1 dfs global t if is_visited[node]:
        return

     is_visited[node] is_visited node return is_visited[node] = True is_visited[node] is_visited node True d[node] = t d[node] d node t t += 1 t 1 for no in DG[node]:
        dfs(no)
     no DG[node] DG node dfs(no) dfs no f[node] = t f[node] f node t t += 1 t 1 node node for node in node_ls:
    dfs(node)

#print(d,f) node node_ls dfs(node) dfs node for node in node_ls:
    print(node, d[node], f[node]) node node_ls print(node, d[node], f[node]) print node d[node] d node f[node] f node node_id = tmp[0] tmp[0] node_id node_ls = [] [] node_ls tmp = input().split() input().split() tmp d = {} {} d t = 1 1 t adj_num = int(tmp[1]) int(tmp[1]) adj_num N = int(input()) int(input()) N is_visited = {} {} is_visited DG = {} {} DG def dfs(node):
    global t
    #終了条件
    if is_visited[node]:
        return

    is_visited[node] = True
    d[node] = t
    t += 1
    for no in DG[node]:
        dfs(no)
    f[node] = t
    t += 1 def dfs(node):
    global t
    #終了条件
    if is_visited[node]:
        return

    is_visited[node] = True
    d[node] = t
    t += 1
    for no in DG[node]:
        dfs(no)
    f[node] = t
    t += 1 dfs f = {} {} f
N = int(input())
DG = {}
node_ls = []
is_visited = {}
#有効グラフをdictで管理することにする
for _ in range(N):
    tmp = input().split()
    node_id = tmp[0]
    node_ls.append(node_id)
    is_visited[node_id] = False
    adj_num = int(tmp[1])#各頂点の次元が入っている
    if adj_num != 0:
        DG[node_id] = tmp[2:]
    else:
        DG[node_id] = []


d = {}#最初に発見したときの時刻を記録
f = {}#隣接リストを調べ終えたときの完了時刻を記録
t = 1

def dfs(node):
    global t
    #終了条件
    if is_visited[node]:
        return

    is_visited[node] = True
    d[node] = t
    t += 1
    for no in DG[node]:
        dfs(no)
    f[node] = t
    t += 1

for node in node_ls:
    dfs(node)

#print(d,f)
for node in node_ls:
    print(node, d[node], f[node])

