d_num = int(input())

graph = [[] for _ in range(d_num+1)]
for _ in range(d_num):
    u, k, *neighbors = map(int, input().split())
    graph[u] = neighbors

visited = set()
timestamps = [None for _ in range(d_num+1)]

def dfs(u, stmp):
    visited.add(u)
    entry = stmp

    stmp += 1
    for v in graph[u]:
        if v not in visited:
            stmp = dfs(v, stmp)

    timestamps[u] = entry, stmp
    return stmp+1

stmp = 1
for v in range(1, d_num+1):
    if v not in visited:
        stmp = dfs(v, stmp)

for num, (entry, leave) in enumerate(timestamps[1:], 1):
    print(num, entry, leave) d_num = int(input()) d_num int(input()) int input() input [] for _ in range(d_num+1) for _ in range(d_num+1) _ range(d_num+1) range d_num+1 d_num 1 for _ in range(d_num+1) [] graph = [[] for _ in range(d_num+1)] graph [[] for _ in range(d_num+1)] for _ in range(d_num):
    u, k, *neighbors = map(int, input().split())
    graph[u] = neighbors _ range(d_num) range d_num u, k, *neighbors = map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split k *neighbors neighbors graph[u] = neighbors graph[u] graph u neighbors visited = set() visited set() set None for _ in range(d_num+1) for _ in range(d_num+1) _ range(d_num+1) range d_num+1 d_num 1 for _ in range(d_num+1) None timestamps = [None for _ in range(d_num+1)] timestamps [None for _ in range(d_num+1)] def dfs(u, stmp):
    visited.add(u)
    entry = stmp

    stmp += 1
    for v in graph[u]:
        if v not in visited:
            stmp = dfs(v, stmp)

    timestamps[u] = entry, stmp
    return stmp+1 dfs visited.add(u) visited.add visited add u entry = stmp entry stmp stmp += 1 stmp 1 for v in graph[u]:
        if v not in visited:
            stmp = dfs(v, stmp)

     v graph[u] graph u if v not in visited:
            stmp = dfs(v, stmp)

     v not in visited v visited stmp = dfs(v, stmp) stmp dfs(v, stmp) dfs v stmp timestamps[u] = entry, stmp timestamps[u] timestamps u timestamps[u] = entry, stmp entry stmp return stmp+1 stmp+1 stmp 1 u u stmp stmp stmp = 1 stmp 1 for v in range(1, d_num+1):
    if v not in visited:
        stmp = dfs(v, stmp) v range(1, d_num+1) range 1 d_num+1 d_num 1 if v not in visited:
        stmp = dfs(v, stmp) v not in visited v visited stmp = dfs(v, stmp) stmp dfs(v, stmp) dfs v stmp for num, (entry, leave) in enumerate(timestamps[1:], 1):
    print(num, entry, leave) num (entry, leave) entry leave enumerate(timestamps[1:], 1) enumerate timestamps[1:] timestamps 1: 1 1 print(num, entry, leave) print num entry leave visited = set() set() visited d_num = int(input()) int(input()) d_num u, k, *neighbors = map(int, input().split()) map(int, input().split()) u timestamps = [None for _ in range(d_num+1)] [None for _ in range(d_num+1)] timestamps graph = [[] for _ in range(d_num+1)] [[] for _ in range(d_num+1)] graph stmp = 1 1 stmp stmp = dfs(v, stmp) dfs(v, stmp) stmp def dfs(u, stmp):
    visited.add(u)
    entry = stmp

    stmp += 1
    for v in graph[u]:
        if v not in visited:
            stmp = dfs(v, stmp)

    timestamps[u] = entry, stmp
    return stmp+1 def dfs(u, stmp):
    visited.add(u)
    entry = stmp

    stmp += 1
    for v in graph[u]:
        if v not in visited:
            stmp = dfs(v, stmp)

    timestamps[u] = entry, stmp
    return stmp+1 dfs k, *neighbors = map(int, input().split()) map(int, input().split()) k
d_num = int(input())

graph = [[] for _ in range(d_num+1)]
for _ in range(d_num):
    u, k, *neighbors = map(int, input().split())
    graph[u] = neighbors

visited = set()
timestamps = [None for _ in range(d_num+1)]

def dfs(u, stmp):
    visited.add(u)
    entry = stmp

    stmp += 1
    for v in graph[u]:
        if v not in visited:
            stmp = dfs(v, stmp)

    timestamps[u] = entry, stmp
    return stmp+1

stmp = 1
for v in range(1, d_num+1):
    if v not in visited:
        stmp = dfs(v, stmp)

for num, (entry, leave) in enumerate(timestamps[1:], 1):
    print(num, entry, leave)
