n = int(input())

adj = [None]
for i in range(n):
    adj_i = list(map(int, input().split()[2:]))
    adj.append(adj_i)

# searched or not, number of vertex, discovery time and finishing time.
sndf = [None]
for i in range(1, n + 1):
    sndf.append([False, i])

path = []

time = 0

def dfs(u):
    global time
    sndf[u][0] = True
    time += 1
    sndf[u].append(time)

    for v in adj[u]:
        if not sndf[v][0]:
            dfs(v)
    sndf[u][0] = True
    time += 1
    sndf[u].append(time)


for i in range(1, n + 1):
    if not sndf[i][0]:
        dfs(i)

for x in sndf[1:]:
    print(*x[1:]) n = int(input()) n int(input()) int input() input adj = [None] adj [None] None for i in range(n):
    adj_i = list(map(int, input().split()[2:]))
    adj.append(adj_i)

# searched or not, number of vertex, discovery time and finishing time. i range(n) range n adj_i = list(map(int, input().split()[2:])) adj_i list(map(int, input().split()[2:])) list map(int, input().split()[2:]) map int input().split()[2:] ().split() ().split () input split 2: 2 adj.append(adj_i) adj.append adj append adj_i sndf = [None] sndf [None] None for i in range(1, n + 1):
    sndf.append([False, i]) i range(1, n + 1) range 1 n + 1 n 1 sndf.append([False, i]) sndf.append sndf append [False, i] False i path = [] path [] time = 0 time 0 def dfs(u):
    global time
    sndf[u][0] = True
    time += 1
    sndf[u].append(time)

    for v in adj[u]:
        if not sndf[v][0]:
            dfs(v)
    sndf[u][0] = True
    time += 1
    sndf[u].append(time) dfs global time sndf[u][0] = True sndf[u][0] [u] sndf u 0 True time += 1 time 1 sndf[u].append(time) [u].append [u] sndf u append time for v in adj[u]:
        if not sndf[v][0]:
            dfs(v)
     v adj[u] adj u if not sndf[v][0]:
            dfs(v)
     not sndf[v][0] sndf[v][0] [v] sndf v 0 dfs(v) dfs v sndf[u][0] = True sndf[u][0] [u] sndf u 0 True time += 1 time 1 sndf[u].append(time) [u].append [u] sndf u append time 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 def dfs(u):
    global time
    sndf[u][0] = True
    time += 1
    sndf[u].append(time)

    for v in adj[u]:
        if not sndf[v][0]:
            dfs(v)
    sndf[u][0] = True
    time += 1
    sndf[u].append(time) def dfs(u):
    global time
    sndf[u][0] = True
    time += 1
    sndf[u].append(time)

    for v in adj[u]:
        if not sndf[v][0]:
            dfs(v)
    sndf[u][0] = True
    time += 1
    sndf[u].append(time) dfs time = 0 0 time n = int(input()) int(input()) n adj_i = list(map(int, input().split()[2:])) list(map(int, input().split()[2:])) adj_i adj = [None] [None] adj sndf = [None] [None] sndf path = [] [] path
n = int(input())

adj = [None]
for i in range(n):
    adj_i = list(map(int, input().split()[2:]))
    adj.append(adj_i)

# searched or not, number of vertex, discovery time and finishing time.
sndf = [None]
for i in range(1, n + 1):
    sndf.append([False, i])

path = []

time = 0

def dfs(u):
    global time
    sndf[u][0] = True
    time += 1
    sndf[u].append(time)

    for v in adj[u]:
        if not sndf[v][0]:
            dfs(v)
    sndf[u][0] = True
    time += 1
    sndf[u].append(time)


for i in range(1, n + 1):
    if not sndf[i][0]:
        dfs(i)

for x in sndf[1:]:
    print(*x[1:])