# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

N=INT()
nodes=[[] for i in range(N)]
for i in range(N):
    l=LIST()
    u=l[0]
    l=l[2:]
    for v in l:
        nodes[u-1].append(v-1)
    nodes[u-1].sort()

ans=[[0]*2 for i in range(N)]
visited=[False]*N
time=0
def rec(u):
    if visited[u]:
        return
    visited[u]=True
    global time
    time+=1
    ans[u][0]=time
    for v in nodes[u]:
        rec(v)
    time+=1
    ans[u][1]=time

for i in range(N):
    rec(i)
for i in range(N):
    d,f=ans[i]
    print(i+1, d, f)
 import sys sys sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 def input(): return sys.stdin.readline().strip() input def INT(): return int(input()) INT def MAP(): return map(int, input().split()) MAP def LIST(): return list(map(int, input().split())) LIST INF=float('inf') INF float('inf') float 'inf' N=INT() N INT() INT [] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [] nodes=[[] for i in range(N)] nodes [[] for i in range(N)] for i in range(N):
    l=LIST()
    u=l[0]
    l=l[2:]
    for v in l:
        nodes[u-1].append(v-1)
    nodes[u-1].sort() i range(N) range N l=LIST() l LIST() LIST u=l[0] u l[0] l 0 l=l[2:] l l[2:] l 2: 2 for v in l:
        nodes[u-1].append(v-1)
     v l nodes[u-1].append(v-1) [u-1].append [u-1] nodes u-1 u 1 append v-1 v 1 nodes[u-1].sort() [u-1].sort [u-1] nodes u-1 u 1 sort [0]*2 for i in range(N) for i in range(N) i range(N) range N for i in range(N) [0]*2 [0] 0 2 ans=[[0]*2 for i in range(N)] ans [[0]*2 for i in range(N)] visited=[False]*N visited [False]*N [False] False N time=0 time 0 def rec(u):
    if visited[u]:
        return
    visited[u]=True
    global time
    time+=1
    ans[u][0]=time
    for v in nodes[u]:
        rec(v)
    time+=1
    ans[u][1]=time rec if visited[u]:
        return
     visited[u] visited u return visited[u]=True visited[u] visited u True global time time+=1 time 1 ans[u][0]=time ans[u][0] [u] ans u 0 time for v in nodes[u]:
        rec(v)
     v nodes[u] nodes u rec(v) rec v time+=1 time 1 ans[u][1]=time ans[u][1] [u] ans u 1 time u u for i in range(N):
    rec(i) i range(N) range N rec(i) rec i for i in range(N):
    d,f=ans[i]
    print(i+1, d, f) i range(N) range N d,f=ans[i] d ans[i] ans i f print(i+1, d, f) print i+1 i 1 d f def rec(u):
    if visited[u]:
        return
    visited[u]=True
    global time
    time+=1
    ans[u][0]=time
    for v in nodes[u]:
        rec(v)
    time+=1
    ans[u][1]=time def rec(u):
    if visited[u]:
        return
    visited[u]=True
    global time
    time+=1
    ans[u][0]=time
    for v in nodes[u]:
        rec(v)
    time+=1
    ans[u][1]=time rec def MAP(): return map(int, input().split()) def MAP(): return map(int, input().split()) MAP N=INT() INT() N ans=[[0]*2 for i in range(N)] [[0]*2 for i in range(N)] ans def INT(): return int(input()) def INT(): return int(input()) INT def LIST(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) LIST u=l[0] l[0] u l=LIST() LIST() l f=ans[i] ans[i] f visited=[False]*N [False]*N visited d,f=ans[i] ans[i] d time=0 0 time INF=float('inf') float('inf') INF nodes=[[] for i in range(N)] [[] for i in range(N)] nodes l=l[2:] l[2:] l def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

N=INT()
nodes=[[] for i in range(N)]
for i in range(N):
    l=LIST()
    u=l[0]
    l=l[2:]
    for v in l:
        nodes[u-1].append(v-1)
    nodes[u-1].sort()

ans=[[0]*2 for i in range(N)]
visited=[False]*N
time=0
def rec(u):
    if visited[u]:
        return
    visited[u]=True
    global time
    time+=1
    ans[u][0]=time
    for v in nodes[u]:
        rec(v)
    time+=1
    ans[u][1]=time

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

