from collections import Counter
import sys

def input():
    return sys.stdin.readline().strip()

def dfs(v):
    start[v] = lb()
    for w in g[v]:
        if start[w] != None:
            continue
        dfs(w)
    end[v] = lb()

n = int(input())
g = [None] * (n+1)
start = [None] * (n+1)
end = [None] * (n+1)
lb = iter(range(1,2*n+1)).__next__
for _ in range(n):
    u,k,*vk = map(int,input().split())
    g[u] = vk
for v in range(1,n+1):
    if start[v] != None:
        continue
    dfs(v)

for i in range(1,n+1):
    print(i,start[i],end[i]) from collections import Counter import sys sys def input():
    return sys.stdin.readline().strip() input return sys.stdin.readline().strip() sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip def dfs(v):
    start[v] = lb()
    for w in g[v]:
        if start[w] != None:
            continue
        dfs(w)
    end[v] = lb() dfs start[v] = lb() start[v] start v lb() lb for w in g[v]:
        if start[w] != None:
            continue
        dfs(w)
     w g[v] g v if start[w] != None:
            continue
         start[w] != None start[w] start w None continue dfs(w) dfs w end[v] = lb() end[v] end v lb() lb v v n = int(input()) n int(input()) int input() input g = [None] * (n+1) g [None] * (n+1) [None] None n+1 n 1 start = [None] * (n+1) start [None] * (n+1) [None] None n+1 n 1 end = [None] * (n+1) end [None] * (n+1) [None] None n+1 n 1 lb = iter(range(1,2*n+1)).__next__ lb iter(range(1,2*n+1)).__next__ (range(1,2*n+1)) iter range(1,2*n+1) range 1 2*n+1 2*n 2 n 1 __next__ for _ in range(n):
    u,k,*vk = map(int,input().split())
    g[u] = vk _ range(n) range n u,k,*vk = map(int,input().split()) u map(int,input().split()) map int input().split() ().split () input split k *vk vk g[u] = vk g[u] g u vk for v in range(1,n+1):
    if start[v] != None:
        continue
    dfs(v) v range(1,n+1) range 1 n+1 n 1 if start[v] != None:
        continue
     start[v] != None start[v] start v None continue dfs(v) dfs v for i in range(1,n+1):
    print(i,start[i],end[i]) i range(1,n+1) range 1 n+1 n 1 print(i,start[i],end[i]) print i start[i] start i end[i] end i u,k,*vk = map(int,input().split()) map(int,input().split()) u k,*vk = map(int,input().split()) map(int,input().split()) k n = int(input()) int(input()) n g = [None] * (n+1) [None] * (n+1) g end = [None] * (n+1) [None] * (n+1) end start = [None] * (n+1) [None] * (n+1) start def input():
    return sys.stdin.readline().strip() def input():
    return sys.stdin.readline().strip() input lb = iter(range(1,2*n+1)).__next__ iter(range(1,2*n+1)).__next__ lb def dfs(v):
    start[v] = lb()
    for w in g[v]:
        if start[w] != None:
            continue
        dfs(w)
    end[v] = lb() def dfs(v):
    start[v] = lb()
    for w in g[v]:
        if start[w] != None:
            continue
        dfs(w)
    end[v] = lb() dfs
from collections import Counter
import sys

def input():
    return sys.stdin.readline().strip()

def dfs(v):
    start[v] = lb()
    for w in g[v]:
        if start[w] != None:
            continue
        dfs(w)
    end[v] = lb()

n = int(input())
g = [None] * (n+1)
start = [None] * (n+1)
end = [None] * (n+1)
lb = iter(range(1,2*n+1)).__next__
for _ in range(n):
    u,k,*vk = map(int,input().split())
    g[u] = vk
for v in range(1,n+1):
    if start[v] != None:
        continue
    dfs(v)

for i in range(1,n+1):
    print(i,start[i],end[i])
