def dfs(v):  # vを訪問する
    global time
    seen[v] = 1
    start[v] = time
    time += 1

    for next_v in graph[v]:
        if seen[next_v]: continue
        dfs(next_v)
    
    end[v] = time
    time += 1


n = int(input())
graph = []
for _ in range(n):
    line = list(map(int, input().split()))
    graph.append([v - 1 for v in line[2:]])

seen = [0] * n  # 0: 未訪問、1: 訪問済
start = [0] * n
end = [0] * n
time = 1

for v in range(n):
    if not seen[v]: dfs(v)

for i in range(n):
    print(i+1, start[i], end[i])
 def dfs(v):  # vを訪問する
    global time
    seen[v] = 1
    start[v] = time
    time += 1

    for next_v in graph[v]:
        if seen[next_v]: continue
        dfs(next_v)
    
    end[v] = time
    time += 1 dfs global time seen[v] = 1 seen[v] seen v 1 start[v] = time start[v] start v time time += 1 time 1 for next_v in graph[v]:
        if seen[next_v]: continue
        dfs(next_v)
    
     next_v graph[v] graph v if seen[next_v]: continue
         seen[next_v] seen next_v dfs(next_v) dfs next_v end[v] = time end[v] end v time time += 1 time 1 v v n = int(input()) n int(input()) int input() input graph = [] graph [] for _ in range(n):
    line = list(map(int, input().split()))
    graph.append([v - 1 for v in line[2:]]) _ range(n) range n line = list(map(int, input().split())) line list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split v - 1 for v in line[2:] for v in line[2:] v line[2:] line 2: 2 for v in line[2:] v - 1 v 1 graph.append([v - 1 for v in line[2:]]) graph.append graph append [v - 1 for v in line[2:]] seen = [0] * n seen [0] * n [0] 0 n start = [0] * n start [0] * n [0] 0 n end = [0] * n end [0] * n [0] 0 n time = 1 time 1 for v in range(n):
    if not seen[v]: dfs(v) v range(n) range n if not seen[v]: df not seen[v] seen[v] seen v for i in range(n):
    print(i+1, start[i], end[i]) i range(n) range n print(i+1, start[i], end[i]) print i+1 i 1 start[i] start i end[i] end i def dfs(v):  # vを訪問する
    global time
    seen[v] = 1
    start[v] = time
    time += 1

    for next_v in graph[v]:
        if seen[next_v]: continue
        dfs(next_v)
    
    end[v] = time
    time += 1 def dfs(v):  # vを訪問する
    global time
    seen[v] = 1
    start[v] = time
    time += 1

    for next_v in graph[v]:
        if seen[next_v]: continue
        dfs(next_v)
    
    end[v] = time
    time += 1 dfs seen = [0] * n [0] * n seen graph = [] [] graph time = 1 1 time line = list(map(int, input().split())) list(map(int, input().split())) line start = [0] * n [0] * n start end = [0] * n [0] * n end n = int(input()) int(input()) n
def dfs(v):  # vを訪問する
    global time
    seen[v] = 1
    start[v] = time
    time += 1

    for next_v in graph[v]:
        if seen[next_v]: continue
        dfs(next_v)
    
    end[v] = time
    time += 1


n = int(input())
graph = []
for _ in range(n):
    line = list(map(int, input().split()))
    graph.append([v - 1 for v in line[2:]])

seen = [0] * n  # 0: 未訪問、1: 訪問済
start = [0] * n
end = [0] * n
time = 1

for v in range(n):
    if not seen[v]: dfs(v)

for i in range(n):
    print(i+1, start[i], end[i])

