n = int(input())
Adj = [[0 for i in range(n)] for i in range(n)]
 
for i in range(n):
    u = list(map(int, input().split()))
    if u[1] > 0:
        for i in u[2: 2 + u[1]]:
            Adj[u[0] - 1][i - 1] = 1
 
color = [0] * n
d = [0] * n
f = [0] * n
time = 0
def dfs(u):
    global time
    color[u - 1] = 1
    time += 1
    d[u - 1] = time
    for i in range(1, n+1):
        if Adj[u - 1][i - 1] == 1 and color[i - 1] == 0:
            dfs(i)
    color[u - 1] = 2
    time += 1
    f[u - 1] = time

for i in range(1, n+1):
    if color[i-1] == 0:
        dfs(i)
for i in range(n):
    print("{} {} {}".format(i+1,d[i],f[i])) 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)] Adj = [[0 for i in range(n)] for i in range(n)] Adj [[0 for i in range(n)] for i in range(n)] for i in range(n):
    u = list(map(int, input().split()))
    if u[1] > 0:
        for i in u[2: 2 + u[1]]:
            Adj[u[0] - 1][i - 1] = 1
  i range(n) range n u = list(map(int, input().split())) u list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split if u[1] > 0:
        for i in u[2: 2 + u[1]]:
            Adj[u[0] - 1][i - 1] = 1
  u[1] > 0 u[1] u 1 0 for i in u[2: 2 + u[1]]:
            Adj[u[0] - 1][i - 1] = 1
  i u[2: 2 + u[1]] u 2: 2 + u[1] 2 2 + u[1] 2 u[1] u 1 Adj[u[0] - 1][i - 1] = 1 Adj[u[0] - 1][i - 1] [u[0] - 1] Adj u[0] - 1 u[0] u 0 1 i - 1 i 1 1 color = [0] * n color [0] * n [0] 0 n d = [0] * n d [0] * n [0] 0 n f = [0] * n f [0] * n [0] 0 n time = 0 time 0 def dfs(u):
    global time
    color[u - 1] = 1
    time += 1
    d[u - 1] = time
    for i in range(1, n+1):
        if Adj[u - 1][i - 1] == 1 and color[i - 1] == 0:
            dfs(i)
    color[u - 1] = 2
    time += 1
    f[u - 1] = time dfs global time color[u - 1] = 1 color[u - 1] color u - 1 u 1 1 time += 1 time 1 d[u - 1] = time d[u - 1] d u - 1 u 1 time for i in range(1, n+1):
        if Adj[u - 1][i - 1] == 1 and color[i - 1] == 0:
            dfs(i)
     i range(1, n+1) range 1 n+1 n 1 if Adj[u - 1][i - 1] == 1 and color[i - 1] == 0:
            dfs(i)
     Adj[u - 1][i - 1] == 1 and color[i - 1] == 0 Adj[u - 1][i - 1] == 1 Adj[u - 1][i - 1] [u - 1] Adj u - 1 u 1 i - 1 i 1 1 color[i - 1] == 0 color[i - 1] color i - 1 i 1 0 dfs(i) dfs i color[u - 1] = 2 color[u - 1] color u - 1 u 1 2 time += 1 time 1 f[u - 1] = time f[u - 1] f u - 1 u 1 time u u for i in range(1, n+1):
    if color[i-1] == 0:
        dfs(i) i range(1, n+1) range 1 n+1 n 1 if color[i-1] == 0:
        dfs(i) color[i-1] == 0 color[i-1] color i-1 i 1 0 dfs(i) dfs i for i in range(n):
    print("{} {} {}".format(i+1,d[i],f[i])) i range(n) range n print("{} {} {}".format(i+1,d[i],f[i])) print "{} {} {}".format(i+1,d[i],f[i]) "{} {} {}".format "{} {} {}" format i+1 i 1 d[i] d i f[i] f i d = [0] * n [0] * n d def dfs(u):
    global time
    color[u - 1] = 1
    time += 1
    d[u - 1] = time
    for i in range(1, n+1):
        if Adj[u - 1][i - 1] == 1 and color[i - 1] == 0:
            dfs(i)
    color[u - 1] = 2
    time += 1
    f[u - 1] = time def dfs(u):
    global time
    color[u - 1] = 1
    time += 1
    d[u - 1] = time
    for i in range(1, n+1):
        if Adj[u - 1][i - 1] == 1 and color[i - 1] == 0:
            dfs(i)
    color[u - 1] = 2
    time += 1
    f[u - 1] = time dfs u = list(map(int, input().split())) list(map(int, input().split())) u n = int(input()) int(input()) n f = [0] * n [0] * n f time = 0 0 time color = [0] * n [0] * n color Adj = [[0 for i in range(n)] for i in range(n)] [[0 for i in range(n)] for i in range(n)] Adj
n = int(input())
Adj = [[0 for i in range(n)] for i in range(n)]
 
for i in range(n):
    u = list(map(int, input().split()))
    if u[1] > 0:
        for i in u[2: 2 + u[1]]:
            Adj[u[0] - 1][i - 1] = 1
 
color = [0] * n
d = [0] * n
f = [0] * n
time = 0
def dfs(u):
    global time
    color[u - 1] = 1
    time += 1
    d[u - 1] = time
    for i in range(1, n+1):
        if Adj[u - 1][i - 1] == 1 and color[i - 1] == 0:
            dfs(i)
    color[u - 1] = 2
    time += 1
    f[u - 1] = time

for i in range(1, n+1):
    if color[i-1] == 0:
        dfs(i)
for i in range(n):
    print("{} {} {}".format(i+1,d[i],f[i]))