import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())

adj = [[] for _ in range(N)]

for i in range(N):
    line = list(map(int, input().split()))
    u = line[0] - 1
    if line[1] == 0:
        continue
    vs = line[2:]
    for v in vs:
        adj[u].append(v - 1)

d = [-1] * N
f = [-1] * N

def dfs(v, t):
    d[v] = t
    nx = t + 1
    for u in adj[v]:
        if d[u] > -1:
            continue
        nx = dfs(u, nx)
    f[v] = nx
    return f[v] + 1

nx = 1
for i in range(N):
    if d[i] > - 1:
        continue
    nx = dfs(i, nx)

for i in range(N):
    print(i + 1, d[i], f[i])
 import sys sys import itertools itertools import time time import math math sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 from collections import defaultdict read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines 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) [] adj = [[] for _ in range(N)] adj [[] for _ in range(N)] for i in range(N):
    line = list(map(int, input().split()))
    u = line[0] - 1
    if line[1] == 0:
        continue
    vs = line[2:]
    for v in vs:
        adj[u].append(v - 1) i 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 u = line[0] - 1 u line[0] - 1 line[0] line 0 1 if line[1] == 0:
        continue
     line[1] == 0 line[1] line 1 0 continue vs = line[2:] vs line[2:] line 2: 2 for v in vs:
        adj[u].append(v - 1) v vs adj[u].append(v - 1) [u].append [u] adj u append v - 1 v 1 d = [-1] * N d [-1] * N [-1] -1 N f = [-1] * N f [-1] * N [-1] -1 N def dfs(v, t):
    d[v] = t
    nx = t + 1
    for u in adj[v]:
        if d[u] > -1:
            continue
        nx = dfs(u, nx)
    f[v] = nx
    return f[v] + 1 dfs d[v] = t d[v] d v t nx = t + 1 nx t + 1 t 1 for u in adj[v]:
        if d[u] > -1:
            continue
        nx = dfs(u, nx)
     u adj[v] adj v if d[u] > -1:
            continue
         d[u] > -1 d[u] d u -1 continue nx = dfs(u, nx) nx dfs(u, nx) dfs u nx f[v] = nx f[v] f v nx return f[v] + 1 f[v] + 1 f[v] f v 1 v v t t nx = 1 nx 1 for i in range(N):
    if d[i] > - 1:
        continue
    nx = dfs(i, nx) i range(N) range N if d[i] > - 1:
        continue
     d[i] > - 1 d[i] d i - 1 continue nx = dfs(i, nx) nx dfs(i, nx) dfs i nx for i in range(N):
    print(i + 1, d[i], f[i]) i range(N) range N print(i + 1, d[i], f[i]) print i + 1 i 1 d[i] d i f[i] f i readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines nx = 1 1 nx adj = [[] for _ in range(N)] [[] for _ in range(N)] adj f = [-1] * N [-1] * N f u = line[0] - 1 line[0] - 1 u N = int(input()) int(input()) N read = sys.stdin.buffer.read sys.stdin.buffer.read read line = list(map(int, input().split())) list(map(int, input().split())) line readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline nx = dfs(i, nx) dfs(i, nx) nx vs = line[2:] line[2:] vs d = [-1] * N [-1] * N d def dfs(v, t):
    d[v] = t
    nx = t + 1
    for u in adj[v]:
        if d[u] > -1:
            continue
        nx = dfs(u, nx)
    f[v] = nx
    return f[v] + 1 def dfs(v, t):
    d[v] = t
    nx = t + 1
    for u in adj[v]:
        if d[u] > -1:
            continue
        nx = dfs(u, nx)
    f[v] = nx
    return f[v] + 1 dfs
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())

adj = [[] for _ in range(N)]

for i in range(N):
    line = list(map(int, input().split()))
    u = line[0] - 1
    if line[1] == 0:
        continue
    vs = line[2:]
    for v in vs:
        adj[u].append(v - 1)

d = [-1] * N
f = [-1] * N

def dfs(v, t):
    d[v] = t
    nx = t + 1
    for u in adj[v]:
        if d[u] > -1:
            continue
        nx = dfs(u, nx)
    f[v] = nx
    return f[v] + 1

nx = 1
for i in range(N):
    if d[i] > - 1:
        continue
    nx = dfs(i, nx)

for i in range(N):
    print(i + 1, d[i], f[i])

