import sys
sys.setrecursionlimit(3000)

n = int(input())
X = []
for _ in range(n):
    x = list(map(int, input().split()))
    if x[1] != 0:
        X.append(x[2:])
    else:
        X.append([])

df = [[0, 0] for _ in range(n)]
t = 0
def search(i = 0):
    global t
    if df[i][0] == 0:
        t += 1
        df[i][0] = t
    for x in X[i]:
        if df[x - 1][0] == 0:
            search(x - 1)
    if df[i][1] == 0:
        t += 1
        df[i][1] = t

for i in range(n):
    search(i)

for i, x in enumerate(df):
    print('{} {} {}'.format(i + 1, x[0], x[1])) import sys sys sys.setrecursionlimit(3000) sys.setrecursionlimit sys setrecursionlimit 3000 n = int(input()) n int(input()) int input() input X = [] X [] for _ in range(n):
    x = list(map(int, input().split()))
    if x[1] != 0:
        X.append(x[2:])
    else:
        X.append([]) _ range(n) range n x = list(map(int, input().split())) x list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split if x[1] != 0:
        X.append(x[2:])
    else:
        X.append([]) x[1] != 0 x[1] x 1 0 X.append(x[2:]) X.append X append x[2:] x 2: 2 X.append([]) X.append X append [] [0, 0] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0, 0] 0 0 df = [[0, 0] for _ in range(n)] df [[0, 0] for _ in range(n)] t = 0 t 0 def search(i = 0):
    global t
    if df[i][0] == 0:
        t += 1
        df[i][0] = t
    for x in X[i]:
        if df[x - 1][0] == 0:
            search(x - 1)
    if df[i][1] == 0:
        t += 1
        df[i][1] = t search global t if df[i][0] == 0:
        t += 1
        df[i][0] = t
     df[i][0] == 0 df[i][0] [i] df i 0 0 t += 1 t 1 df[i][0] = t df[i][0] [i] df i 0 t for x in X[i]:
        if df[x - 1][0] == 0:
            search(x - 1)
     x X[i] X i if df[x - 1][0] == 0:
            search(x - 1)
     df[x - 1][0] == 0 df[x - 1][0] [x - 1] df x - 1 x 1 0 0 search(x - 1) search x - 1 x 1 if df[i][1] == 0:
        t += 1
        df[i][1] = t df[i][1] == 0 df[i][1] [i] df i 1 0 t += 1 t 1 df[i][1] = t df[i][1] [i] df i 1 t i = 0 i 0 for i in range(n):
    search(i) i range(n) range n search(i) search i for i, x in enumerate(df):
    print('{} {} {}'.format(i + 1, x[0], x[1])) i x enumerate(df) enumerate df print('{} {} {}'.format(i + 1, x[0], x[1])) print '{} {} {}'.format(i + 1, x[0], x[1]) '{} {} {}'.format '{} {} {}' format i + 1 i 1 x[0] x 0 x[1] x 1 n = int(input()) int(input()) n X = [] [] X def search(i = 0):
    global t
    if df[i][0] == 0:
        t += 1
        df[i][0] = t
    for x in X[i]:
        if df[x - 1][0] == 0:
            search(x - 1)
    if df[i][1] == 0:
        t += 1
        df[i][1] = t def search(i = 0):
    global t
    if df[i][0] == 0:
        t += 1
        df[i][0] = t
    for x in X[i]:
        if df[x - 1][0] == 0:
            search(x - 1)
    if df[i][1] == 0:
        t += 1
        df[i][1] = t search x = list(map(int, input().split())) list(map(int, input().split())) x t = 0 0 t df = [[0, 0] for _ in range(n)] [[0, 0] for _ in range(n)] df
import sys
sys.setrecursionlimit(3000)

n = int(input())
X = []
for _ in range(n):
    x = list(map(int, input().split()))
    if x[1] != 0:
        X.append(x[2:])
    else:
        X.append([])

df = [[0, 0] for _ in range(n)]
t = 0
def search(i = 0):
    global t
    if df[i][0] == 0:
        t += 1
        df[i][0] = t
    for x in X[i]:
        if df[x - 1][0] == 0:
            search(x - 1)
    if df[i][1] == 0:
        t += 1
        df[i][1] = t

for i in range(n):
    search(i)

for i, x in enumerate(df):
    print('{} {} {}'.format(i + 1, x[0], x[1]))
