from collections import deque
import sys
input = sys.stdin.readline


N = int(input())
G = [[] for _ in range(N)]
for _ in range(N):
    ls = list(map(int, input().split()))
    u = ls[0] - 1
    for v in ls[2:]:
        G[u].append(v - 1)

time = 1
d = [None for _ in range(N)]
f = [None for _ in range(N)]

def dfs(v):
    global time
    d[v] = time
    time += 1
    
    for u in range(N):
        if u in G[v]:
            if d[u] is None:
                dfs(u)

    f[v] = time
    time += 1

for v in range(N):
    if d[v] is None:
        dfs(v)

for v in range(N):
    print("{} {} {}".format(v + 1, d[v], f[v])) from collections import deque import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N = int(input()) N int(input()) int input() input [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] G = [[] for _ in range(N)] G [[] for _ in range(N)] for _ in range(N):
    ls = list(map(int, input().split()))
    u = ls[0] - 1
    for v in ls[2:]:
        G[u].append(v - 1) _ range(N) range N ls = list(map(int, input().split())) ls list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split u = ls[0] - 1 u ls[0] - 1 ls[0] ls 0 1 for v in ls[2:]:
        G[u].append(v - 1) v ls[2:] ls 2: 2 G[u].append(v - 1) [u].append [u] G u append v - 1 v 1 time = 1 time 1 None for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) None d = [None for _ in range(N)] d [None for _ in range(N)] None for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) None f = [None for _ in range(N)] f [None for _ in range(N)] def dfs(v):
    global time
    d[v] = time
    time += 1
    
    for u in range(N):
        if u in G[v]:
            if d[u] is None:
                dfs(u)

    f[v] = time
    time += 1 dfs global time d[v] = time d[v] d v time time += 1 time 1 for u in range(N):
        if u in G[v]:
            if d[u] is None:
                dfs(u)

     u range(N) range N if u in G[v]:
            if d[u] is None:
                dfs(u)

     u in G[v] u G[v] G v if d[u] is None:
                dfs(u)

     d[u] is None d[u] d u None dfs(u) dfs u f[v] = time f[v] f v time time += 1 time 1 v v for v in range(N):
    if d[v] is None:
        dfs(v) v range(N) range N if d[v] is None:
        dfs(v) d[v] is None d[v] d v None dfs(v) dfs v for v in range(N):
    print("{} {} {}".format(v + 1, d[v], f[v])) v range(N) range N print("{} {} {}".format(v + 1, d[v], f[v])) print "{} {} {}".format(v + 1, d[v], f[v]) "{} {} {}".format "{} {} {}" format v + 1 v 1 d[v] d v f[v] f v input = sys.stdin.readline sys.stdin.readline input ls = list(map(int, input().split())) list(map(int, input().split())) ls f = [None for _ in range(N)] [None for _ in range(N)] f def dfs(v):
    global time
    d[v] = time
    time += 1
    
    for u in range(N):
        if u in G[v]:
            if d[u] is None:
                dfs(u)

    f[v] = time
    time += 1 def dfs(v):
    global time
    d[v] = time
    time += 1
    
    for u in range(N):
        if u in G[v]:
            if d[u] is None:
                dfs(u)

    f[v] = time
    time += 1 dfs time = 1 1 time N = int(input()) int(input()) N G = [[] for _ in range(N)] [[] for _ in range(N)] G d = [None for _ in range(N)] [None for _ in range(N)] d u = ls[0] - 1 ls[0] - 1 u
from collections import deque
import sys
input = sys.stdin.readline


N = int(input())
G = [[] for _ in range(N)]
for _ in range(N):
    ls = list(map(int, input().split()))
    u = ls[0] - 1
    for v in ls[2:]:
        G[u].append(v - 1)

time = 1
d = [None for _ in range(N)]
f = [None for _ in range(N)]

def dfs(v):
    global time
    d[v] = time
    time += 1
    
    for u in range(N):
        if u in G[v]:
            if d[u] is None:
                dfs(u)

    f[v] = time
    time += 1

for v in range(N):
    if d[v] is None:
        dfs(v)

for v in range(N):
    print("{} {} {}".format(v + 1, d[v], f[v]))
