N = int(input())

Graph = {}
Node_list = []
visited = {}
d = {}
f = {}
t = 1

for i in range(N):
    
    tmp = input().split()
    id = tmp[0]
    Node_list.append(id)
    visited[id] = False

    if int(tmp[1]) != 0:
        Graph[id] = tmp[2:]
    else:
        Graph[id] = []
 


def dfs(node):
    global t

    if visited[node]:
        return

    visited[node] = True

    d[node] = t
    t += 1

    for no in Graph[node]:
        dfs(no)

    f[node] = t
    t += 1

for node in Node_list:
    dfs(node)

for node in Node_list:
    print(node, d[node], f[node])
    
    
    
    
    
     N = int(input()) N int(input()) int input() input Graph = {} Graph {} Node_list = [] Node_list [] visited = {} visited {} d = {} d {} f = {} f {} t = 1 t 1 for i in range(N):
    
    tmp = input().split()
    id = tmp[0]
    Node_list.append(id)
    visited[id] = False

    if int(tmp[1]) != 0:
        Graph[id] = tmp[2:]
    else:
        Graph[id] = []
  i range(N) range N tmp = input().split() tmp input().split() ().split () input split id = tmp[0] id tmp[0] tmp 0 Node_list.append(id) Node_list.append Node_list append id visited[id] = False visited[id] visited id False if int(tmp[1]) != 0:
        Graph[id] = tmp[2:]
    else:
        Graph[id] = []
  int(tmp[1]) != 0 int(tmp[1]) int tmp[1] tmp 1 0 Graph[id] = tmp[2:] Graph[id] Graph id tmp[2:] tmp 2: 2 Graph[id] = [] Graph[id] Graph id [] def dfs(node):
    global t

    if visited[node]:
        return

    visited[node] = True

    d[node] = t
    t += 1

    for no in Graph[node]:
        dfs(no)

    f[node] = t
    t += 1 dfs global t if visited[node]:
        return

     visited[node] visited node return visited[node] = True visited[node] visited node True d[node] = t d[node] d node t t += 1 t 1 for no in Graph[node]:
        dfs(no)

     no Graph[node] Graph node dfs(no) dfs no f[node] = t f[node] f node t t += 1 t 1 node node for node in Node_list:
    dfs(node) node Node_list dfs(node) dfs node for node in Node_list:
    print(node, d[node], f[node])
    
    
    
    
    
     node Node_list print(node, d[node], f[node]) print node d[node] d node f[node] f node visited = {} {} visited tmp = input().split() input().split() tmp Node_list = [] [] Node_list d = {} {} d Graph = {} {} Graph f = {} {} f N = int(input()) int(input()) N t = 1 1 t def dfs(node):
    global t

    if visited[node]:
        return

    visited[node] = True

    d[node] = t
    t += 1

    for no in Graph[node]:
        dfs(no)

    f[node] = t
    t += 1 def dfs(node):
    global t

    if visited[node]:
        return

    visited[node] = True

    d[node] = t
    t += 1

    for no in Graph[node]:
        dfs(no)

    f[node] = t
    t += 1 dfs id = tmp[0] tmp[0] id
N = int(input())

Graph = {}
Node_list = []
visited = {}
d = {}
f = {}
t = 1

for i in range(N):
    
    tmp = input().split()
    id = tmp[0]
    Node_list.append(id)
    visited[id] = False

    if int(tmp[1]) != 0:
        Graph[id] = tmp[2:]
    else:
        Graph[id] = []
 


def dfs(node):
    global t

    if visited[node]:
        return

    visited[node] = True

    d[node] = t
    t += 1

    for no in Graph[node]:
        dfs(no)

    f[node] = t
    t += 1

for node in Node_list:
    dfs(node)

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