#ALDS_11_B - 深さ優先探索
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)#再帰回数の上限

def DFS(u, cnt):
    visited.add(u)
    first_contact = cnt
    
    cnt += 1
    for nb in edge[u]:
        if nb not in visited:
            cnt = DFS(nb, cnt)
    
    stamp[u] = first_contact, cnt
    return cnt+1
    

N = int(input())
edge = [[] for i in range(N)]
for _ in range(N):
    tmp = list(map(int,input().split()))
    if tmp[1] != 0:
        edge[tmp[0]-1] = list(map(lambda x: int(x-1),tmp[2:]))

stamp = [None]*N
visited = set()

c = 1
for i in range(N):
    if i not in visited:
        c = DFS(i, c)
        
for i,s in enumerate(stamp):
    print(i+1,*s) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 def DFS(u, cnt):
    visited.add(u)
    first_contact = cnt
    
    cnt += 1
    for nb in edge[u]:
        if nb not in visited:
            cnt = DFS(nb, cnt)
    
    stamp[u] = first_contact, cnt
    return cnt+1
     DFS visited.add(u) visited.add visited add u first_contact = cnt first_contact cnt cnt += 1 cnt 1 for nb in edge[u]:
        if nb not in visited:
            cnt = DFS(nb, cnt)
    
     nb edge[u] edge u if nb not in visited:
            cnt = DFS(nb, cnt)
    
     nb not in visited nb visited cnt = DFS(nb, cnt) cnt DFS(nb, cnt) DFS nb cnt stamp[u] = first_contact, cnt stamp[u] stamp u stamp[u] = first_contact, cnt first_contact cnt return cnt+1 cnt+1 cnt 1 u u cnt cnt N = int(input()) N int(input()) int input() input [] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [] edge = [[] for i in range(N)] edge [[] for i in range(N)] for _ in range(N):
    tmp = list(map(int,input().split()))
    if tmp[1] != 0:
        edge[tmp[0]-1] = list(map(lambda x: int(x-1),tmp[2:])) _ range(N) range N tmp = list(map(int,input().split())) tmp list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split if tmp[1] != 0:
        edge[tmp[0]-1] = list(map(lambda x: int(x-1),tmp[2:])) tmp[1] != 0 tmp[1] tmp 1 0 edge[tmp[0]-1] = list(map(lambda x: int(x-1),tmp[2:])) edge[tmp[0]-1] edge tmp[0]-1 tmp[0] tmp 0 1 list(map(lambda x: int(x-1),tmp[2:])) list map(lambda x: int(x-1),tmp[2:]) map lambda x: int(x-1) int(x-1) int x-1 x 1 x tmp[2:] tmp 2: 2 stamp = [None]*N stamp [None]*N [None] None N visited = set() visited set() set c = 1 c 1 for i in range(N):
    if i not in visited:
        c = DFS(i, c)
         i range(N) range N if i not in visited:
        c = DFS(i, c)
         i not in visited i visited c = DFS(i, c) c DFS(i, c) DFS i c for i,s in enumerate(stamp):
    print(i+1,*s) i s enumerate(stamp) enumerate stamp print(i+1,*s) print i+1 i 1 *s s visited = set() set() visited def DFS(u, cnt):
    visited.add(u)
    first_contact = cnt
    
    cnt += 1
    for nb in edge[u]:
        if nb not in visited:
            cnt = DFS(nb, cnt)
    
    stamp[u] = first_contact, cnt
    return cnt+1
     def DFS(u, cnt):
    visited.add(u)
    first_contact = cnt
    
    cnt += 1
    for nb in edge[u]:
        if nb not in visited:
            cnt = DFS(nb, cnt)
    
    stamp[u] = first_contact, cnt
    return cnt+1
     DFS c = 1 1 c c = DFS(i, c) DFS(i, c) c tmp = list(map(int,input().split())) list(map(int,input().split())) tmp input = sys.stdin.readline sys.stdin.readline input stamp = [None]*N [None]*N stamp N = int(input()) int(input()) N edge = [[] for i in range(N)] [[] for i in range(N)] edge
#ALDS_11_B - 深さ優先探索
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)#再帰回数の上限

def DFS(u, cnt):
    visited.add(u)
    first_contact = cnt
    
    cnt += 1
    for nb in edge[u]:
        if nb not in visited:
            cnt = DFS(nb, cnt)
    
    stamp[u] = first_contact, cnt
    return cnt+1
    

N = int(input())
edge = [[] for i in range(N)]
for _ in range(N):
    tmp = list(map(int,input().split()))
    if tmp[1] != 0:
        edge[tmp[0]-1] = list(map(lambda x: int(x-1),tmp[2:]))

stamp = [None]*N
visited = set()

c = 1
for i in range(N):
    if i not in visited:
        c = DFS(i, c)
        
for i,s in enumerate(stamp):
    print(i+1,*s)
