def dfs(index):
    global count
    d[index] = count
    count += 1
    for i in field[index]:
        if d[i]:
            continue
        count = dfs(i)
    f[index] = count
    return count + 1

n = int(input())
field = [[0,0]]
for _ in range(n):
    u, k, *v = map(int, input().split())
    field.append(v)
d = [0 for _ in range(n + 1)]
f = [0 for _ in range(n + 1)]

count = 1
for i in range(1, n + 1):
    if d[i]:
        continue
    count = dfs(i)
for i in range(1, n + 1):
    print(i, d[i], f[i]) def dfs(index):
    global count
    d[index] = count
    count += 1
    for i in field[index]:
        if d[i]:
            continue
        count = dfs(i)
    f[index] = count
    return count + 1 dfs global count d[index] = count d[index] d index count count += 1 count 1 for i in field[index]:
        if d[i]:
            continue
        count = dfs(i)
     i field[index] field index if d[i]:
            continue
         d[i] d i continue count = dfs(i) count dfs(i) dfs i f[index] = count f[index] f index count return count + 1 count + 1 count 1 index index n = int(input()) n int(input()) int input() input field = [[0,0]] field [[0,0]] [0,0] 0 0 for _ in range(n):
    u, k, *v = map(int, input().split())
    field.append(v) _ range(n) range n u, k, *v = map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split k *v v field.append(v) field.append field append v 0 for _ in range(n + 1) for _ in range(n + 1) _ range(n + 1) range n + 1 n 1 for _ in range(n + 1) 0 d = [0 for _ in range(n + 1)] d [0 for _ in range(n + 1)] 0 for _ in range(n + 1) for _ in range(n + 1) _ range(n + 1) range n + 1 n 1 for _ in range(n + 1) 0 f = [0 for _ in range(n + 1)] f [0 for _ in range(n + 1)] count = 1 count 1 for i in range(1, n + 1):
    if d[i]:
        continue
    count = dfs(i) i range(1, n + 1) range 1 n + 1 n 1 if d[i]:
        continue
     d[i] d i continue count = dfs(i) count dfs(i) dfs 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 k, *v = map(int, input().split()) map(int, input().split()) k d = [0 for _ in range(n + 1)] [0 for _ in range(n + 1)] d u, k, *v = map(int, input().split()) map(int, input().split()) u count = 1 1 count def dfs(index):
    global count
    d[index] = count
    count += 1
    for i in field[index]:
        if d[i]:
            continue
        count = dfs(i)
    f[index] = count
    return count + 1 def dfs(index):
    global count
    d[index] = count
    count += 1
    for i in field[index]:
        if d[i]:
            continue
        count = dfs(i)
    f[index] = count
    return count + 1 dfs count = dfs(i) dfs(i) count n = int(input()) int(input()) n field = [[0,0]] [[0,0]] field f = [0 for _ in range(n + 1)] [0 for _ in range(n + 1)] f
def dfs(index):
    global count
    d[index] = count
    count += 1
    for i in field[index]:
        if d[i]:
            continue
        count = dfs(i)
    f[index] = count
    return count + 1

n = int(input())
field = [[0,0]]
for _ in range(n):
    u, k, *v = map(int, input().split())
    field.append(v)
d = [0 for _ in range(n + 1)]
f = [0 for _ in range(n + 1)]

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