from sys import stdin
n = int(stdin.readline())
M = [None]
M += [list(map(int, stdin.readline().split()[2:])) for i in range(n)]
sndf = [None]
sndf += [[False, i] for i in range(1, n + 1)]
tt = 0
def dfs(u):
    global tt
    sndf[u][0] = True
    tt += 1
    sndf[u].append(tt)
    for v in M[u]:
        if not sndf[v][0]:
            dfs(v)
    tt += 1
    sndf[u].append(tt)
for i in range(1, n + 1):
    if not sndf[i][0]:
        dfs(i)
for x in sndf[1:]:
    print(*x[1:]) from sys import stdin n = int(stdin.readline()) n int(stdin.readline()) int stdin.readline() stdin.readline stdin readline M = [None] M [None] None list(map(int, stdin.readline().split()[2:])) for i in range(n) for i in range(n) i range(n) range n for i in range(n) list(map(int, stdin.readline().split()[2:])) list map(int, stdin.readline().split()[2:]) map int stdin.readline().split()[2:] stdin.readline().split() stdin.readline().split stdin.readline() stdin.readline stdin readline split 2: 2 M += [list(map(int, stdin.readline().split()[2:])) for i in range(n)] M [list(map(int, stdin.readline().split()[2:])) for i in range(n)] sndf = [None] sndf [None] None [False, i] for i in range(1, n + 1) for i in range(1, n + 1) i range(1, n + 1) range 1 n + 1 n 1 for i in range(1, n + 1) [False, i] False i sndf += [[False, i] for i in range(1, n + 1)] sndf [[False, i] for i in range(1, n + 1)] tt = 0 tt 0 def dfs(u):
    global tt
    sndf[u][0] = True
    tt += 1
    sndf[u].append(tt)
    for v in M[u]:
        if not sndf[v][0]:
            dfs(v)
    tt += 1
    sndf[u].append(tt) dfs global tt sndf[u][0] = True sndf[u][0] [u] sndf u 0 True tt += 1 tt 1 sndf[u].append(tt) [u].append [u] sndf u append tt for v in M[u]:
        if not sndf[v][0]:
            dfs(v)
     v M[u] M u if not sndf[v][0]:
            dfs(v)
     not sndf[v][0] sndf[v][0] [v] sndf v 0 dfs(v) dfs v tt += 1 tt 1 sndf[u].append(tt) [u].append [u] sndf u append tt u u for i in range(1, n + 1):
    if not sndf[i][0]:
        dfs(i) i range(1, n + 1) range 1 n + 1 n 1 if not sndf[i][0]:
        dfs(i) not sndf[i][0] sndf[i][0] [i] sndf i 0 dfs(i) dfs i for x in sndf[1:]:
    print(*x[1:]) x sndf[1:] sndf 1: 1 print(*x[1:]) print *x[1:] x[1:] x 1: 1 sndf += [[False, i] for i in range(1, n + 1)] [[False, i] for i in range(1, n + 1)] sndf def dfs(u):
    global tt
    sndf[u][0] = True
    tt += 1
    sndf[u].append(tt)
    for v in M[u]:
        if not sndf[v][0]:
            dfs(v)
    tt += 1
    sndf[u].append(tt) def dfs(u):
    global tt
    sndf[u][0] = True
    tt += 1
    sndf[u].append(tt)
    for v in M[u]:
        if not sndf[v][0]:
            dfs(v)
    tt += 1
    sndf[u].append(tt) dfs n = int(stdin.readline()) int(stdin.readline()) n tt = 0 0 tt M += [list(map(int, stdin.readline().split()[2:])) for i in range(n)] [list(map(int, stdin.readline().split()[2:])) for i in range(n)] M M = [None] [None] M sndf = [None] [None] sndf
from sys import stdin
n = int(stdin.readline())
M = [None]
M += [list(map(int, stdin.readline().split()[2:])) for i in range(n)]
sndf = [None]
sndf += [[False, i] for i in range(1, n + 1)]
tt = 0
def dfs(u):
    global tt
    sndf[u][0] = True
    tt += 1
    sndf[u].append(tt)
    for v in M[u]:
        if not sndf[v][0]:
            dfs(v)
    tt += 1
    sndf[u].append(tt)
for i in range(1, n + 1):
    if not sndf[i][0]:
        dfs(i)
for x in sndf[1:]:
    print(*x[1:])