n = int(input())
a = [[0]*n for i in range(n)]
  
for i in range(n):
    v = list(map(int, input().split()))
    u = v[0]
    k = v[1]
    for j in range(k):
        a[u - 1][v[2 + j] - 1] = 1

d = [0] * n
f = [0] * n
isDiscovered = [False] * n
time_stamp = 0

def dfs(x):
    global time_stamp
    isDiscovered [x] = True
    time_stamp = time_stamp + 1
    d[x] = time_stamp
    for i in range(n):
        if a[x][i] == 1 and isDiscovered[i] == False:
            dfs(i)
    time_stamp = time_stamp + 1
    f[x] = time_stamp

for i in range(n):
    if isDiscovered[i] == False:
        dfs(i)

for i in range(n):
    print(i+1, d[i], f[i]) n = int(input()) n int(input()) int input() input [0]*n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [0]*n [0] 0 n a = [[0]*n for i in range(n)] a [[0]*n for i in range(n)] for i in range(n):
    v = list(map(int, input().split()))
    u = v[0]
    k = v[1]
    for j in range(k):
        a[u - 1][v[2 + j] - 1] = 1 i range(n) range n v = list(map(int, input().split())) v list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split u = v[0] u v[0] v 0 k = v[1] k v[1] v 1 for j in range(k):
        a[u - 1][v[2 + j] - 1] = 1 j range(k) range k a[u - 1][v[2 + j] - 1] = 1 a[u - 1][v[2 + j] - 1] [u - 1] a u - 1 u 1 v[2 + j] - 1 v[2 + j] v 2 + j 2 j 1 1 d = [0] * n d [0] * n [0] 0 n f = [0] * n f [0] * n [0] 0 n isDiscovered = [False] * n isDiscovered [False] * n [False] False n time_stamp = 0 time_stamp 0 def dfs(x):
    global time_stamp
    isDiscovered [x] = True
    time_stamp = time_stamp + 1
    d[x] = time_stamp
    for i in range(n):
        if a[x][i] == 1 and isDiscovered[i] == False:
            dfs(i)
    time_stamp = time_stamp + 1
    f[x] = time_stamp dfs global time_stamp isDiscovered [x] = True isDiscovered [x] isDiscovered x True time_stamp = time_stamp + 1 time_stamp time_stamp + 1 time_stamp 1 d[x] = time_stamp d[x] d x time_stamp for i in range(n):
        if a[x][i] == 1 and isDiscovered[i] == False:
            dfs(i)
     i range(n) range n if a[x][i] == 1 and isDiscovered[i] == False:
            dfs(i)
     a[x][i] == 1 and isDiscovered[i] == False a[x][i] == 1 a[x][i] [x] a x i 1 isDiscovered[i] == False isDiscovered[i] isDiscovered i False dfs(i) dfs i time_stamp = time_stamp + 1 time_stamp time_stamp + 1 time_stamp 1 f[x] = time_stamp f[x] f x time_stamp x x for i in range(n):
    if isDiscovered[i] == False:
        dfs(i) i range(n) range n if isDiscovered[i] == False:
        dfs(i) isDiscovered[i] == False isDiscovered[i] isDiscovered i False dfs(i) dfs i for i in range(n):
    print(i+1, d[i], f[i]) i range(n) range n print(i+1, d[i], f[i]) print i+1 i 1 d[i] d i f[i] f i a = [[0]*n for i in range(n)] [[0]*n for i in range(n)] a k = v[1] v[1] k u = v[0] v[0] u n = int(input()) int(input()) n time_stamp = 0 0 time_stamp def dfs(x):
    global time_stamp
    isDiscovered [x] = True
    time_stamp = time_stamp + 1
    d[x] = time_stamp
    for i in range(n):
        if a[x][i] == 1 and isDiscovered[i] == False:
            dfs(i)
    time_stamp = time_stamp + 1
    f[x] = time_stamp def dfs(x):
    global time_stamp
    isDiscovered [x] = True
    time_stamp = time_stamp + 1
    d[x] = time_stamp
    for i in range(n):
        if a[x][i] == 1 and isDiscovered[i] == False:
            dfs(i)
    time_stamp = time_stamp + 1
    f[x] = time_stamp dfs f = [0] * n [0] * n f v = list(map(int, input().split())) list(map(int, input().split())) v d = [0] * n [0] * n d isDiscovered = [False] * n [False] * n isDiscovered
n = int(input())
a = [[0]*n for i in range(n)]
  
for i in range(n):
    v = list(map(int, input().split()))
    u = v[0]
    k = v[1]
    for j in range(k):
        a[u - 1][v[2 + j] - 1] = 1

d = [0] * n
f = [0] * n
isDiscovered = [False] * n
time_stamp = 0

def dfs(x):
    global time_stamp
    isDiscovered [x] = True
    time_stamp = time_stamp + 1
    d[x] = time_stamp
    for i in range(n):
        if a[x][i] == 1 and isDiscovered[i] == False:
            dfs(i)
    time_stamp = time_stamp + 1
    f[x] = time_stamp

for i in range(n):
    if isDiscovered[i] == False:
        dfs(i)

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