def dfs(n):
    global t
    S[n] = t
    DP[n]=1
    for i in A[n][2:]:
        if not DP[i]:
            t += 1
            dfs(i)
    t += 1
    F[n] = t
n = int(input())
A = [0]*(n+1)
S = [0]*(n+1)
F = [0]*(n+1)
DP = [0]*(n+1)
for i in range(n):
    A[i+1] = [int(i) for i in input().split()]
t = 0
for i in range(1,n+1):
    if not DP[i]:
        t+=1
        dfs(i)
for i in range(1,n+1):
    tmp = "{} {} {}".format(i,S[i],F[i])
    print(tmp) def dfs(n):
    global t
    S[n] = t
    DP[n]=1
    for i in A[n][2:]:
        if not DP[i]:
            t += 1
            dfs(i)
    t += 1
    F[n] = t dfs global t S[n] = t S[n] S n t DP[n]=1 DP[n] DP n 1 for i in A[n][2:]:
        if not DP[i]:
            t += 1
            dfs(i)
     i A[n][2:] [n] A n 2: 2 if not DP[i]:
            t += 1
            dfs(i)
     not DP[i] DP[i] DP i t += 1 t 1 dfs(i) dfs i t += 1 t 1 F[n] = t F[n] F n t n n n = int(input()) n int(input()) int input() input A = [0]*(n+1) A [0]*(n+1) [0] 0 n+1 n 1 S = [0]*(n+1) S [0]*(n+1) [0] 0 n+1 n 1 F = [0]*(n+1) F [0]*(n+1) [0] 0 n+1 n 1 DP = [0]*(n+1) DP [0]*(n+1) [0] 0 n+1 n 1 for i in range(n):
    A[i+1] = [int(i) for i in input().split()] i range(n) range n int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i A[i+1] = [int(i) for i in input().split()] A[i+1] A i+1 i 1 [int(i) for i in input().split()] t = 0 t 0 for i in range(1,n+1):
    if not DP[i]:
        t+=1
        dfs(i) i range(1,n+1) range 1 n+1 n 1 if not DP[i]:
        t+=1
        dfs(i) not DP[i] DP[i] DP i t+=1 t 1 dfs(i) dfs i for i in range(1,n+1):
    tmp = "{} {} {}".format(i,S[i],F[i])
    print(tmp) i range(1,n+1) range 1 n+1 n 1 tmp = "{} {} {}".format(i,S[i],F[i]) tmp "{} {} {}".format(i,S[i],F[i]) "{} {} {}".format "{} {} {}" format i S[i] S i F[i] F i print(tmp) print tmp A = [0]*(n+1) [0]*(n+1) A t = 0 0 t n = int(input()) int(input()) n DP = [0]*(n+1) [0]*(n+1) DP S = [0]*(n+1) [0]*(n+1) S def dfs(n):
    global t
    S[n] = t
    DP[n]=1
    for i in A[n][2:]:
        if not DP[i]:
            t += 1
            dfs(i)
    t += 1
    F[n] = t def dfs(n):
    global t
    S[n] = t
    DP[n]=1
    for i in A[n][2:]:
        if not DP[i]:
            t += 1
            dfs(i)
    t += 1
    F[n] = t dfs F = [0]*(n+1) [0]*(n+1) F t+=1 1 t tmp = "{} {} {}".format(i,S[i],F[i]) "{} {} {}".format(i,S[i],F[i]) tmp
def dfs(n):
    global t
    S[n] = t
    DP[n]=1
    for i in A[n][2:]:
        if not DP[i]:
            t += 1
            dfs(i)
    t += 1
    F[n] = t
n = int(input())
A = [0]*(n+1)
S = [0]*(n+1)
F = [0]*(n+1)
DP = [0]*(n+1)
for i in range(n):
    A[i+1] = [int(i) for i in input().split()]
t = 0
for i in range(1,n+1):
    if not DP[i]:
        t+=1
        dfs(i)
for i in range(1,n+1):
    tmp = "{} {} {}".format(i,S[i],F[i])
    print(tmp)
