j = 1

def dfs(graph, start, result, visited=None):
    global j
    if visited == None:
        visited = []
    visited.append(start)
    result[start][1]  = j
    for next in graph[start][2:]:
        if next in visited:
            continue
        j += 1
        dfs(graph, next, result, visited)
    else:
        j += 1
        result[start][2] = j

n = int(input())
g = [[]]
r = [[i,0,0] for i in range(n + 1)]
v = []

for i in range(n):
    g.append(list(map(int, input().split())))


for i in range(1, n + 1):
    if i in v:
        continue
    dfs(g,i,r,v)
    j += 1

for i in range(1,n+1):
    print(*r[i]) j = 1 j 1 def dfs(graph, start, result, visited=None):
    global j
    if visited == None:
        visited = []
    visited.append(start)
    result[start][1]  = j
    for next in graph[start][2:]:
        if next in visited:
            continue
        j += 1
        dfs(graph, next, result, visited)
    else:
        j += 1
        result[start][2] = j dfs global j if visited == None:
        visited = []
     visited == None visited None visited = [] visited [] visited.append(start) visited.append visited append start result[start][1]  = j result[start][1] [start] result start 1 j for next in graph[start][2:]:
        if next in visited:
            continue
        j += 1
        dfs(graph, next, result, visited)
    else:
        j += 1
        result[start][2] = j next graph[start][2:] [start] graph start 2: 2 if next in visited:
            continue
         next in visited next visited continue j += 1 j 1 dfs(graph, next, result, visited) dfs graph next result visited j += 1 j 1 result[start][2] = j result[start][2] [start] result start 2 j graph graph start start result result visited=None visited None n = int(input()) n int(input()) int input() input g = [[]] g [[]] [] [i,0,0] for i in range(n + 1) for i in range(n + 1) i range(n + 1) range n + 1 n 1 for i in range(n + 1) [i,0,0] i 0 0 r = [[i,0,0] for i in range(n + 1)] r [[i,0,0] for i in range(n + 1)] v = [] v [] for i in range(n):
    g.append(list(map(int, input().split()))) i range(n) range n g.append(list(map(int, input().split()))) g.append g append list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split for i in range(1, n + 1):
    if i in v:
        continue
    dfs(g,i,r,v)
    j += 1 i range(1, n + 1) range 1 n + 1 n 1 if i in v:
        continue
     i in v i v continue dfs(g,i,r,v) dfs g i r v j += 1 j 1 for i in range(1,n+1):
    print(*r[i]) i range(1,n+1) range 1 n+1 n 1 print(*r[i]) print *r[i] r[i] r i j += 1 1 j j = 1 1 j r = [[i,0,0] for i in range(n + 1)] [[i,0,0] for i in range(n + 1)] r v = [] [] v def dfs(graph, start, result, visited=None):
    global j
    if visited == None:
        visited = []
    visited.append(start)
    result[start][1]  = j
    for next in graph[start][2:]:
        if next in visited:
            continue
        j += 1
        dfs(graph, next, result, visited)
    else:
        j += 1
        result[start][2] = j def dfs(graph, start, result, visited=None):
    global j
    if visited == None:
        visited = []
    visited.append(start)
    result[start][1]  = j
    for next in graph[start][2:]:
        if next in visited:
            continue
        j += 1
        dfs(graph, next, result, visited)
    else:
        j += 1
        result[start][2] = j dfs n = int(input()) int(input()) n g = [[]] [[]] g
j = 1

def dfs(graph, start, result, visited=None):
    global j
    if visited == None:
        visited = []
    visited.append(start)
    result[start][1]  = j
    for next in graph[start][2:]:
        if next in visited:
            continue
        j += 1
        dfs(graph, next, result, visited)
    else:
        j += 1
        result[start][2] = j

n = int(input())
g = [[]]
r = [[i,0,0] for i in range(n + 1)]
v = []

for i in range(n):
    g.append(list(map(int, input().split())))


for i in range(1, n + 1):
    if i in v:
        continue
    dfs(g,i,r,v)
    j += 1

for i in range(1,n+1):
    print(*r[i])