def dfs(num, lst, d, f, cnt):
    if d[num] != 0:
        return cnt - 1
    d[num] = cnt
    for n in lst[num]:
        cnt += 1
        cnt = dfs(n - 1, lst, d, f ,cnt)
    cnt += 1
    f[num] = cnt
    return cnt


n = int(input())
d = [0 for i in range(n)]
f = [0 for i in range(n)]
lst = []
for _ in range(n):
    n = list(map(int, input().split()))
    lst.append(n[2:])

cnt = 1
while 0 in d:
    num = d.index(0)
    cnt = dfs(num, lst, d, f, cnt) + 1

for i, j in enumerate(zip(d, f)):
    print(i + 1, j[0], j[1]) def dfs(num, lst, d, f, cnt):
    if d[num] != 0:
        return cnt - 1
    d[num] = cnt
    for n in lst[num]:
        cnt += 1
        cnt = dfs(n - 1, lst, d, f ,cnt)
    cnt += 1
    f[num] = cnt
    return cnt dfs if d[num] != 0:
        return cnt - 1
     d[num] != 0 d[num] d num 0 return cnt - 1 cnt - 1 cnt 1 d[num] = cnt d[num] d num cnt for n in lst[num]:
        cnt += 1
        cnt = dfs(n - 1, lst, d, f ,cnt)
     n lst[num] lst num cnt += 1 cnt 1 cnt = dfs(n - 1, lst, d, f ,cnt) cnt dfs(n - 1, lst, d, f ,cnt) dfs n - 1 n 1 lst d f cnt cnt += 1 cnt 1 f[num] = cnt f[num] f num cnt return cnt cnt num num lst lst d d f f cnt cnt n = int(input()) n int(input()) int input() input 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 d = [0 for i in range(n)] d [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 f = [0 for i in range(n)] f [0 for i in range(n)] lst = [] lst [] for _ in range(n):
    n = list(map(int, input().split()))
    lst.append(n[2:]) _ range(n) range n n = list(map(int, input().split())) n list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split lst.append(n[2:]) lst.append lst append n[2:] n 2: 2 cnt = 1 cnt 1 while 0 in d:
    num = d.index(0)
    cnt = dfs(num, lst, d, f, cnt) + 1 0 in d 0 d num = d.index(0) num d.index(0) d.index d index 0 cnt = dfs(num, lst, d, f, cnt) + 1 cnt dfs(num, lst, d, f, cnt) + 1 dfs(num, lst, d, f, cnt) dfs num lst d f cnt 1 for i, j in enumerate(zip(d, f)):
    print(i + 1, j[0], j[1]) i j enumerate(zip(d, f)) enumerate zip(d, f) zip d f print(i + 1, j[0], j[1]) print i + 1 i 1 j[0] j 0 j[1] j 1 lst = [] [] lst n = int(input()) int(input()) n f = [0 for i in range(n)] [0 for i in range(n)] f num = d.index(0) d.index(0) num d = [0 for i in range(n)] [0 for i in range(n)] d n = list(map(int, input().split())) list(map(int, input().split())) n cnt = 1 1 cnt cnt = dfs(num, lst, d, f, cnt) + 1 dfs(num, lst, d, f, cnt) + 1 cnt def dfs(num, lst, d, f, cnt):
    if d[num] != 0:
        return cnt - 1
    d[num] = cnt
    for n in lst[num]:
        cnt += 1
        cnt = dfs(n - 1, lst, d, f ,cnt)
    cnt += 1
    f[num] = cnt
    return cnt def dfs(num, lst, d, f, cnt):
    if d[num] != 0:
        return cnt - 1
    d[num] = cnt
    for n in lst[num]:
        cnt += 1
        cnt = dfs(n - 1, lst, d, f ,cnt)
    cnt += 1
    f[num] = cnt
    return cnt dfs
def dfs(num, lst, d, f, cnt):
    if d[num] != 0:
        return cnt - 1
    d[num] = cnt
    for n in lst[num]:
        cnt += 1
        cnt = dfs(n - 1, lst, d, f ,cnt)
    cnt += 1
    f[num] = cnt
    return cnt


n = int(input())
d = [0 for i in range(n)]
f = [0 for i in range(n)]
lst = []
for _ in range(n):
    n = list(map(int, input().split()))
    lst.append(n[2:])

cnt = 1
while 0 in d:
    num = d.index(0)
    cnt = dfs(num, lst, d, f, cnt) + 1

for i, j in enumerate(zip(d, f)):
    print(i + 1, j[0], j[1])
