n = int(input())
trees = [[]]
for i in range(n):
    edges = []
    s = list(map(int, input().split()))
    num = s[1]
    if s[1] != 0:
        edges = s[2:2+num]
    trees.append(edges)

d = [0] * (n+1)
f = [0] * (n+1)


def dfs(x, i=0):
    for y in trees[x]:
        if d[y] != 0:
            continue
        d[y] = i
        i += 1
        i = dfs(y, i)
    f[x] = i
    i += 1
    return i


i = 1
for j in range(1, n+1):
    if d[j] != 0:
        continue
    else:
        d[j] = i
        i += 1
    i = dfs(j, i)
for i in range(1, n+1):
    print(i, d[i], f[i]) n = int(input()) n int(input()) int input() input trees = [[]] trees [[]] [] for i in range(n):
    edges = []
    s = list(map(int, input().split()))
    num = s[1]
    if s[1] != 0:
        edges = s[2:2+num]
    trees.append(edges) i range(n) range n edges = [] edges [] s = list(map(int, input().split())) s list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split num = s[1] num s[1] s 1 if s[1] != 0:
        edges = s[2:2+num]
     s[1] != 0 s[1] s 1 0 edges = s[2:2+num] edges s[2:2+num] s 2:2+num 2 2+num 2 num trees.append(edges) trees.append trees append edges d = [0] * (n+1) d [0] * (n+1) [0] 0 n+1 n 1 f = [0] * (n+1) f [0] * (n+1) [0] 0 n+1 n 1 def dfs(x, i=0):
    for y in trees[x]:
        if d[y] != 0:
            continue
        d[y] = i
        i += 1
        i = dfs(y, i)
    f[x] = i
    i += 1
    return i dfs for y in trees[x]:
        if d[y] != 0:
            continue
        d[y] = i
        i += 1
        i = dfs(y, i)
     y trees[x] trees x if d[y] != 0:
            continue
         d[y] != 0 d[y] d y 0 continue d[y] = i d[y] d y i i += 1 i 1 i = dfs(y, i) i dfs(y, i) dfs y i f[x] = i f[x] f x i i += 1 i 1 return i i x x i=0 i 0 i = 1 i 1 for j in range(1, n+1):
    if d[j] != 0:
        continue
    else:
        d[j] = i
        i += 1
    i = dfs(j, i) j range(1, n+1) range 1 n+1 n 1 if d[j] != 0:
        continue
    else:
        d[j] = i
        i += 1
     d[j] != 0 d[j] d j 0 continue d[j] = i d[j] d j i i += 1 i 1 i = dfs(j, i) i dfs(j, i) dfs j i for i in range(1, n+1):
    print(i, d[i], f[i]) i range(1, n+1) range 1 n+1 n 1 print(i, d[i], f[i]) print i d[i] d i f[i] f i edges = s[2:2+num] s[2:2+num] edges s = list(map(int, input().split())) list(map(int, input().split())) s trees = [[]] [[]] trees i = dfs(j, i) dfs(j, i) i def dfs(x, i=0):
    for y in trees[x]:
        if d[y] != 0:
            continue
        d[y] = i
        i += 1
        i = dfs(y, i)
    f[x] = i
    i += 1
    return i def dfs(x, i=0):
    for y in trees[x]:
        if d[y] != 0:
            continue
        d[y] = i
        i += 1
        i = dfs(y, i)
    f[x] = i
    i += 1
    return i dfs d = [0] * (n+1) [0] * (n+1) d i += 1 1 i f = [0] * (n+1) [0] * (n+1) f edges = [] [] edges n = int(input()) int(input()) n num = s[1] s[1] num i = 1 1 i
n = int(input())
trees = [[]]
for i in range(n):
    edges = []
    s = list(map(int, input().split()))
    num = s[1]
    if s[1] != 0:
        edges = s[2:2+num]
    trees.append(edges)

d = [0] * (n+1)
f = [0] * (n+1)


def dfs(x, i=0):
    for y in trees[x]:
        if d[y] != 0:
            continue
        d[y] = i
        i += 1
        i = dfs(y, i)
    f[x] = i
    i += 1
    return i


i = 1
for j in range(1, n+1):
    if d[j] != 0:
        continue
    else:
        d[j] = i
        i += 1
    i = dfs(j, i)
for i in range(1, n+1):
    print(i, d[i], f[i])
