# 深さ優先探索 Depth first search: DFS


def dfs(u):
    global time
    color[u - 1] = 0
    time += 1
    d[u - 1] = time
    for v in range(1, n + 1):
        if A[u - 1][v - 1] == 1 and color[v - 1] == -1:
            dfs(v)
    color[u - 1] = 1
    time += 1
    f[u - 1] = time


n = int(input())
A = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
    dat = [int(j) for j in input().split()]
    for j in range(dat[1]):
        A[dat[0] - 1][dat[2 + j] - 1] = 1

color = [-1 for i in range(n)]
d = [-1 for i in range(n)]
f = [-1 for i in range(n)]
time = 0
for i in range(n):
    if color[i] == -1:
        dfs(i+1)

for id in range(n):
    print(id + 1, d[id], f[id])
 def dfs(u):
    global time
    color[u - 1] = 0
    time += 1
    d[u - 1] = time
    for v in range(1, n + 1):
        if A[u - 1][v - 1] == 1 and color[v - 1] == -1:
            dfs(v)
    color[u - 1] = 1
    time += 1
    f[u - 1] = time dfs global time color[u - 1] = 0 color[u - 1] color u - 1 u 1 0 time += 1 time 1 d[u - 1] = time d[u - 1] d u - 1 u 1 time for v in range(1, n + 1):
        if A[u - 1][v - 1] == 1 and color[v - 1] == -1:
            dfs(v)
     v range(1, n + 1) range 1 n + 1 n 1 if A[u - 1][v - 1] == 1 and color[v - 1] == -1:
            dfs(v)
     A[u - 1][v - 1] == 1 and color[v - 1] == -1 A[u - 1][v - 1] == 1 A[u - 1][v - 1] [u - 1] A u - 1 u 1 v - 1 v 1 1 color[v - 1] == -1 color[v - 1] color v - 1 v 1 -1 dfs(v) dfs v color[u - 1] = 1 color[u - 1] color u - 1 u 1 1 time += 1 time 1 f[u - 1] = time f[u - 1] f u - 1 u 1 time u u n = int(input()) n int(input()) int input() input [0 for i in range(n)] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [0 for i in range(n)] A = [[0 for i in range(n)] for i in range(n)] A [[0 for i in range(n)] for i in range(n)] for i in range(n):
    dat = [int(j) for j in input().split()]
    for j in range(dat[1]):
        A[dat[0] - 1][dat[2 + j] - 1] = 1 i range(n) range n int(j) for j in input().split() for j in input().split() j input().split() ().split () input split for j in input().split() int(j) int j dat = [int(j) for j in input().split()] dat [int(j) for j in input().split()] for j in range(dat[1]):
        A[dat[0] - 1][dat[2 + j] - 1] = 1 j range(dat[1]) range dat[1] dat 1 A[dat[0] - 1][dat[2 + j] - 1] = 1 A[dat[0] - 1][dat[2 + j] - 1] [dat[0] - 1] A dat[0] - 1 dat[0] dat 0 1 dat[2 + j] - 1 dat[2 + j] dat 2 + j 2 j 1 1 -1 for i in range(n) for i in range(n) i range(n) range n for i in range(n) -1 color = [-1 for i in range(n)] color [-1 for i in range(n)] -1 for i in range(n) for i in range(n) i range(n) range n for i in range(n) -1 d = [-1 for i in range(n)] d [-1 for i in range(n)] -1 for i in range(n) for i in range(n) i range(n) range n for i in range(n) -1 f = [-1 for i in range(n)] f [-1 for i in range(n)] time = 0 time 0 for i in range(n):
    if color[i] == -1:
        dfs(i+1) i range(n) range n if color[i] == -1:
        dfs(i+1) color[i] == -1 color[i] color i -1 dfs(i+1) dfs i+1 i 1 for id in range(n):
    print(id + 1, d[id], f[id]) id range(n) range n print(id + 1, d[id], f[id]) print id + 1 id 1 d[id] d id f[id] f id f = [-1 for i in range(n)] [-1 for i in range(n)] f time = 0 0 time n = int(input()) int(input()) n d = [-1 for i in range(n)] [-1 for i in range(n)] d color = [-1 for i in range(n)] [-1 for i in range(n)] color def dfs(u):
    global time
    color[u - 1] = 0
    time += 1
    d[u - 1] = time
    for v in range(1, n + 1):
        if A[u - 1][v - 1] == 1 and color[v - 1] == -1:
            dfs(v)
    color[u - 1] = 1
    time += 1
    f[u - 1] = time def dfs(u):
    global time
    color[u - 1] = 0
    time += 1
    d[u - 1] = time
    for v in range(1, n + 1):
        if A[u - 1][v - 1] == 1 and color[v - 1] == -1:
            dfs(v)
    color[u - 1] = 1
    time += 1
    f[u - 1] = time dfs dat = [int(j) for j in input().split()] [int(j) for j in input().split()] dat A = [[0 for i in range(n)] for i in range(n)] [[0 for i in range(n)] for i in range(n)] A
# 深さ優先探索 Depth first search: DFS


def dfs(u):
    global time
    color[u - 1] = 0
    time += 1
    d[u - 1] = time
    for v in range(1, n + 1):
        if A[u - 1][v - 1] == 1 and color[v - 1] == -1:
            dfs(v)
    color[u - 1] = 1
    time += 1
    f[u - 1] = time


n = int(input())
A = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
    dat = [int(j) for j in input().split()]
    for j in range(dat[1]):
        A[dat[0] - 1][dat[2 + j] - 1] = 1

color = [-1 for i in range(n)]
d = [-1 for i in range(n)]
f = [-1 for i in range(n)]
time = 0
for i in range(n):
    if color[i] == -1:
        dfs(i+1)

for id in range(n):
    print(id + 1, d[id], f[id])

