import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
time = 1
def dfs(node):
    global time
    if visited[node] != -1:
        return
    visited[node] = 0
    d[node] = time
    time += 1
    for v in edge[node]:
        dfs(v)
    f[node] = time
    time += 1

if __name__ == "__main__":
    n = int(input())
    edge = []
    for i in range(n):
        u,k,*v_li = map(int,input().split())
        for j in range(len(v_li)):
            v_li[j] -= 1
        u-=1
        edge.append(v_li)
    d = {}
    f = {}
    visited = [-1]*n
    
    for i in range(n):
        dfs(i)
    for i in range(n):
        print(i+1,d[i],f[i])

 import sys sys import itertools itertools sys.setrecursionlimit(1000000000) sys.setrecursionlimit sys setrecursionlimit 1000000000 from heapq import heapify,heappop,heappush,heappushpop import math math import collections collections import copy copy time = 1 time 1 def dfs(node):
    global time
    if visited[node] != -1:
        return
    visited[node] = 0
    d[node] = time
    time += 1
    for v in edge[node]:
        dfs(v)
    f[node] = time
    time += 1 dfs global time if visited[node] != -1:
        return
     visited[node] != -1 visited[node] visited node -1 return visited[node] = 0 visited[node] visited node 0 d[node] = time d[node] d node time time += 1 time 1 for v in edge[node]:
        dfs(v)
     v edge[node] edge node dfs(v) dfs v f[node] = time f[node] f node time time += 1 time 1 node node if __name__ == "__main__":
    n = int(input())
    edge = []
    for i in range(n):
        u,k,*v_li = map(int,input().split())
        for j in range(len(v_li)):
            v_li[j] -= 1
        u-=1
        edge.append(v_li)
    d = {}
    f = {}
    visited = [-1]*n
    
    for i in range(n):
        dfs(i)
    for i in range(n):
        print(i+1,d[i],f[i]) __name__ == "__main__" __name__ "__main__" n = int(input()) n int(input()) int input() input edge = [] edge [] for i in range(n):
        u,k,*v_li = map(int,input().split())
        for j in range(len(v_li)):
            v_li[j] -= 1
        u-=1
        edge.append(v_li)
     i range(n) range n u,k,*v_li = map(int,input().split()) u map(int,input().split()) map int input().split() ().split () input split k *v_li v_li for j in range(len(v_li)):
            v_li[j] -= 1
         j range(len(v_li)) range len(v_li) len v_li v_li[j] -= 1 v_li[j] v_li j 1 u-=1 u 1 edge.append(v_li) edge.append edge append v_li d = {} d {} f = {} f {} visited = [-1]*n visited [-1]*n [-1] -1 n for i in range(n):
        dfs(i)
     i range(n) range n 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 f = {} {} f edge = [] [] edge u-=1 1 u time = 1 1 time k,*v_li = map(int,input().split()) map(int,input().split()) k n = int(input()) int(input()) n u,k,*v_li = map(int,input().split()) map(int,input().split()) u visited = [-1]*n [-1]*n visited def dfs(node):
    global time
    if visited[node] != -1:
        return
    visited[node] = 0
    d[node] = time
    time += 1
    for v in edge[node]:
        dfs(v)
    f[node] = time
    time += 1 def dfs(node):
    global time
    if visited[node] != -1:
        return
    visited[node] = 0
    d[node] = time
    time += 1
    for v in edge[node]:
        dfs(v)
    f[node] = time
    time += 1 dfs d = {} {} d
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
time = 1
def dfs(node):
    global time
    if visited[node] != -1:
        return
    visited[node] = 0
    d[node] = time
    time += 1
    for v in edge[node]:
        dfs(v)
    f[node] = time
    time += 1

if __name__ == "__main__":
    n = int(input())
    edge = []
    for i in range(n):
        u,k,*v_li = map(int,input().split())
        for j in range(len(v_li)):
            v_li[j] -= 1
        u-=1
        edge.append(v_li)
    d = {}
    f = {}
    visited = [-1]*n
    
    for i in range(n):
        dfs(i)
    for i in range(n):
        print(i+1,d[i],f[i])


