G = {}
N = int(input())
for _ in range(N):
    L = list(map(int, input().split()))
    G[L[0]] = L[2:]

# print(G)
d = [-1] * N
f = [-1] * N
q = [1]
visited = [False] * N

time = 1


def dfs(v):
    global time
    visited[v-1] = True

    for nv in G[v]:
        if d[nv-1] < 0:
            d[nv-1] = time
            time += 1
        if not visited[nv-1]:
            dfs(nv)

    f[v-1] = time
    time += 1


for i in range(1, N+1):
    if not visited[i-1]:
        d[i-1] = time
        time += 1
        dfs(i)

for i in range(N):
    print(i+1, d[i], f[i])
 G = {} G {} N = int(input()) N int(input()) int input() input for _ in range(N):
    L = list(map(int, input().split()))
    G[L[0]] = L[2:]

# print(G) _ range(N) range N L = list(map(int, input().split())) L list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split G[L[0]] = L[2:] G[L[0]] G L[0] L 0 L[2:] L 2: 2 d = [-1] * N d [-1] * N [-1] -1 N f = [-1] * N f [-1] * N [-1] -1 N q = [1] q [1] 1 visited = [False] * N visited [False] * N [False] False N time = 1 time 1 def dfs(v):
    global time
    visited[v-1] = True

    for nv in G[v]:
        if d[nv-1] < 0:
            d[nv-1] = time
            time += 1
        if not visited[nv-1]:
            dfs(nv)

    f[v-1] = time
    time += 1 dfs global time visited[v-1] = True visited[v-1] visited v-1 v 1 True for nv in G[v]:
        if d[nv-1] < 0:
            d[nv-1] = time
            time += 1
        if not visited[nv-1]:
            dfs(nv)

     nv G[v] G v if d[nv-1] < 0:
            d[nv-1] = time
            time += 1
         d[nv-1] < 0 d[nv-1] d nv-1 nv 1 0 d[nv-1] = time d[nv-1] d nv-1 nv 1 time time += 1 time 1 if not visited[nv-1]:
            dfs(nv)

     not visited[nv-1] visited[nv-1] visited nv-1 nv 1 dfs(nv) dfs nv f[v-1] = time f[v-1] f v-1 v 1 time time += 1 time 1 v v for i in range(1, N+1):
    if not visited[i-1]:
        d[i-1] = time
        time += 1
        dfs(i) i range(1, N+1) range 1 N+1 N 1 if not visited[i-1]:
        d[i-1] = time
        time += 1
        dfs(i) not visited[i-1] visited[i-1] visited i-1 i 1 d[i-1] = time d[i-1] d i-1 i 1 time time += 1 time 1 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 visited = [False] * N [False] * N visited def dfs(v):
    global time
    visited[v-1] = True

    for nv in G[v]:
        if d[nv-1] < 0:
            d[nv-1] = time
            time += 1
        if not visited[nv-1]:
            dfs(nv)

    f[v-1] = time
    time += 1 def dfs(v):
    global time
    visited[v-1] = True

    for nv in G[v]:
        if d[nv-1] < 0:
            d[nv-1] = time
            time += 1
        if not visited[nv-1]:
            dfs(nv)

    f[v-1] = time
    time += 1 dfs time = 1 1 time f = [-1] * N [-1] * N f q = [1] [1] q N = int(input()) int(input()) N time += 1 1 time d = [-1] * N [-1] * N d G = {} {} G L = list(map(int, input().split())) list(map(int, input().split())) L
G = {}
N = int(input())
for _ in range(N):
    L = list(map(int, input().split()))
    G[L[0]] = L[2:]

# print(G)
d = [-1] * N
f = [-1] * N
q = [1]
visited = [False] * N

time = 1


def dfs(v):
    global time
    visited[v-1] = True

    for nv in G[v]:
        if d[nv-1] < 0:
            d[nv-1] = time
            time += 1
        if not visited[nv-1]:
            dfs(nv)

    f[v-1] = time
    time += 1


for i in range(1, N+1):
    if not visited[i-1]:
        d[i-1] = time
        time += 1
        dfs(i)

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

