n = input()

time = []
time.append(0)

d = [0 for i in xrange(n + 1)]
f = [0 for i in xrange(n + 1)]
color = ['WHITE' for i in xrange(n + 1)]

graph_map = [[0 for j in xrange(n + 1)] for i in xrange(n + 1)]

for i in xrange(1, n + 1):
    tmp = map(int, raw_input().split())
    for j in xrange(tmp[1]):
        graph_map[i][tmp[j + 2]] = 1

def dfs(u):
    color[u] = 'GRAY'
    time[0] += 1
    d[u] = time[0]
    for v in xrange(1, n + 1):
        if graph_map[u][v] == 1 and color[v] == 'WHITE':
            dfs(v)
    color[u] = 'BLACK'
    time[0] += 1
    f[u] = time[0]

for i in xrange(1, n + 1):
    if color[i] == 'WHITE':
        dfs(i)

for i in xrange(1, n + 1):
    print "%d %d %d" % (i, d[i], f[i]) n = input() n input() input time = [] time [] time.append(0) time.append time append 0 0 for i in xrange(n + 1) for i in xrange(n + 1) i xrange(n + 1) xrange n + 1 n 1 for i in xrange(n + 1) 0 d = [0 for i in xrange(n + 1)] d [0 for i in xrange(n + 1)] 0 for i in xrange(n + 1) for i in xrange(n + 1) i xrange(n + 1) xrange n + 1 n 1 for i in xrange(n + 1) 0 f = [0 for i in xrange(n + 1)] f [0 for i in xrange(n + 1)] 'WHITE' for i in xrange(n + 1) for i in xrange(n + 1) i xrange(n + 1) xrange n + 1 n 1 for i in xrange(n + 1) 'WHITE' color = ['WHITE' for i in xrange(n + 1)] color ['WHITE' for i in xrange(n + 1)] [0 for j in xrange(n + 1)] for i in xrange(n + 1) for i in xrange(n + 1) i xrange(n + 1) xrange n + 1 n 1 for i in xrange(n + 1) [0 for j in xrange(n + 1)] graph_map = [[0 for j in xrange(n + 1)] for i in xrange(n + 1)] graph_map [[0 for j in xrange(n + 1)] for i in xrange(n + 1)] for i in xrange(1, n + 1):
    tmp = map(int, raw_input().split())
    for j in xrange(tmp[1]):
        graph_map[i][tmp[j + 2]] = 1 i xrange(1, n + 1) xrange 1 n + 1 n 1 tmp = map(int, raw_input().split()) tmp map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split for j in xrange(tmp[1]):
        graph_map[i][tmp[j + 2]] = 1 j xrange(tmp[1]) xrange tmp[1] tmp 1 graph_map[i][tmp[j + 2]] = 1 graph_map[i][tmp[j + 2]] [i] graph_map i tmp[j + 2] tmp j + 2 j 2 1 def dfs(u):
    color[u] = 'GRAY'
    time[0] += 1
    d[u] = time[0]
    for v in xrange(1, n + 1):
        if graph_map[u][v] == 1 and color[v] == 'WHITE':
            dfs(v)
    color[u] = 'BLACK'
    time[0] += 1
    f[u] = time[0] dfs color[u] = 'GRAY' color[u] color u 'GRAY' time[0] += 1 time[0] time 0 1 d[u] = time[0] d[u] d u time[0] time 0 for v in xrange(1, n + 1):
        if graph_map[u][v] == 1 and color[v] == 'WHITE':
            dfs(v)
     v xrange(1, n + 1) xrange 1 n + 1 n 1 if graph_map[u][v] == 1 and color[v] == 'WHITE':
            dfs(v)
     graph_map[u][v] == 1 and color[v] == 'WHITE' graph_map[u][v] == 1 graph_map[u][v] [u] graph_map u v 1 color[v] == 'WHITE' color[v] color v 'WHITE' dfs(v) dfs v color[u] = 'BLACK' color[u] color u 'BLACK' time[0] += 1 time[0] time 0 1 f[u] = time[0] f[u] f u time[0] time 0 u u for i in xrange(1, n + 1):
    if color[i] == 'WHITE':
        dfs(i) i xrange(1, n + 1) xrange 1 n + 1 n 1 if color[i] == 'WHITE':
        dfs(i) color[i] == 'WHITE' color[i] color i 'WHITE' dfs(i) dfs i for i in xrange(1, n + 1):
    print "%d %d %d" % (i, d[i], f[i]) i xrange(1, n + 1) xrange 1 n + 1 n 1 print "%d %d %d" % (i, d[i], f[i]) "%d %d %d" (i, d[i], f[i]) i d[i] d i f[i] f i f = [0 for i in xrange(n + 1)] [0 for i in xrange(n + 1)] f n = input() input() n tmp = map(int, raw_input().split()) map(int, raw_input().split()) tmp color = ['WHITE' for i in xrange(n + 1)] ['WHITE' for i in xrange(n + 1)] color time = [] [] time graph_map = [[0 for j in xrange(n + 1)] for i in xrange(n + 1)] [[0 for j in xrange(n + 1)] for i in xrange(n + 1)] graph_map d = [0 for i in xrange(n + 1)] [0 for i in xrange(n + 1)] d def dfs(u):
    color[u] = 'GRAY'
    time[0] += 1
    d[u] = time[0]
    for v in xrange(1, n + 1):
        if graph_map[u][v] == 1 and color[v] == 'WHITE':
            dfs(v)
    color[u] = 'BLACK'
    time[0] += 1
    f[u] = time[0] def dfs(u):
    color[u] = 'GRAY'
    time[0] += 1
    d[u] = time[0]
    for v in xrange(1, n + 1):
        if graph_map[u][v] == 1 and color[v] == 'WHITE':
            dfs(v)
    color[u] = 'BLACK'
    time[0] += 1
    f[u] = time[0] dfs
n = input()

time = []
time.append(0)

d = [0 for i in xrange(n + 1)]
f = [0 for i in xrange(n + 1)]
color = ['WHITE' for i in xrange(n + 1)]

graph_map = [[0 for j in xrange(n + 1)] for i in xrange(n + 1)]

for i in xrange(1, n + 1):
    tmp = map(int, raw_input().split())
    for j in xrange(tmp[1]):
        graph_map[i][tmp[j + 2]] = 1

def dfs(u):
    color[u] = 'GRAY'
    time[0] += 1
    d[u] = time[0]
    for v in xrange(1, n + 1):
        if graph_map[u][v] == 1 and color[v] == 'WHITE':
            dfs(v)
    color[u] = 'BLACK'
    time[0] += 1
    f[u] = time[0]

for i in xrange(1, n + 1):
    if color[i] == 'WHITE':
        dfs(i)

for i in xrange(1, n + 1):
    print "%d %d %d" % (i, d[i], f[i])