import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

N = I()
adj = [[] for _ in range(N)]
visited = [False for _ in range(N)]
d = [0 for _ in range(N)]
f = [0 for _ in range(N)]
cur_time = 1

for _ in range(N):
    edge_list = LI()
    u, k = edge_list[0], edge_list[1]
    if k == 0:
        continue
    v_list = edge_list[2:]
    u -= 1
    for v in v_list:
        v -= 1
        adj[u].append(v)

def dfs(u):
    global cur_time
    visited[u] = True
    for v in adj[u]:
        if not visited[v]:
            d[v] = cur_time
            cur_time += 1
            dfs(v)
    f[u] = cur_time
    cur_time += 1
    return

for v in range(N):
    if not visited[v]:
        d[v] = cur_time
        cur_time += 1
        dfs(v)

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


 import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools math string itertools fractions heapq collections re array bisect sys random time copy functools from collections import deque sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 inf = 10**20 inf 10**20 10 20 mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 DR = [1, -1, 0, 0] DR [1, -1, 0, 0] 1 -1 0 0 DC = [0, 0, 1, -1] DC [0, 0, 1, -1] 0 0 1 -1 int(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x) int x def LI(): return [int(x) for x in sys.stdin.readline().split()] LI int(x)-1 for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x)-1 int(x) int x 1 def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] LI_ float(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() float(x) float x def LF(): return [float(x) for x in sys.stdin.readline().split()] LF def LS(): return sys.stdin.readline().split() LS def I(): return int(sys.stdin.readline()) I def F(): return float(sys.stdin.readline()) F def S(): return input() S N = I() N I() I [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] adj = [[] for _ in range(N)] adj [[] for _ in range(N)] False for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) False visited = [False for _ in range(N)] visited [False for _ in range(N)] 0 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) 0 d = [0 for _ in range(N)] d [0 for _ in range(N)] 0 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) 0 f = [0 for _ in range(N)] f [0 for _ in range(N)] cur_time = 1 cur_time 1 for _ in range(N):
    edge_list = LI()
    u, k = edge_list[0], edge_list[1]
    if k == 0:
        continue
    v_list = edge_list[2:]
    u -= 1
    for v in v_list:
        v -= 1
        adj[u].append(v) _ range(N) range N edge_list = LI() edge_list LI() LI u, k = edge_list[0], edge_list[1] u edge_list[0] edge_list 0 k edge_list[1] edge_list 1 if k == 0:
        continue
     k == 0 k 0 continue v_list = edge_list[2:] v_list edge_list[2:] edge_list 2: 2 u -= 1 u 1 for v in v_list:
        v -= 1
        adj[u].append(v) v v_list v -= 1 v 1 adj[u].append(v) [u].append [u] adj u append v def dfs(u):
    global cur_time
    visited[u] = True
    for v in adj[u]:
        if not visited[v]:
            d[v] = cur_time
            cur_time += 1
            dfs(v)
    f[u] = cur_time
    cur_time += 1
    return dfs global cur_time visited[u] = True visited[u] visited u True for v in adj[u]:
        if not visited[v]:
            d[v] = cur_time
            cur_time += 1
            dfs(v)
     v adj[u] adj u if not visited[v]:
            d[v] = cur_time
            cur_time += 1
            dfs(v)
     not visited[v] visited[v] visited v d[v] = cur_time d[v] d v cur_time cur_time += 1 cur_time 1 dfs(v) dfs v f[u] = cur_time f[u] f u cur_time cur_time += 1 cur_time 1 return u u for v in range(N):
    if not visited[v]:
        d[v] = cur_time
        cur_time += 1
        dfs(v) v range(N) range N if not visited[v]:
        d[v] = cur_time
        cur_time += 1
        dfs(v) not visited[v] visited[v] visited v d[v] = cur_time d[v] d v cur_time cur_time += 1 cur_time 1 dfs(v) dfs v for v in range(N):
    print(v+1, d[v], f[v]) v range(N) range N print(v+1, d[v], f[v]) print v+1 v 1 d[v] d v f[v] f v u -= 1 1 u def S(): return input() def S(): return input() S cur_time = 1 1 cur_time f = [0 for _ in range(N)] [0 for _ in range(N)] f cur_time += 1 1 cur_time def LF(): return [float(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] LF def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI(): return [int(x) for x in sys.stdin.readline().split()] LI adj = [[] for _ in range(N)] [[] for _ in range(N)] adj def LS(): return sys.stdin.readline().split() def LS(): return sys.stdin.readline().split() LS v -= 1 1 v def F(): return float(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) F def dfs(u):
    global cur_time
    visited[u] = True
    for v in adj[u]:
        if not visited[v]:
            d[v] = cur_time
            cur_time += 1
            dfs(v)
    f[u] = cur_time
    cur_time += 1
    return def dfs(u):
    global cur_time
    visited[u] = True
    for v in adj[u]:
        if not visited[v]:
            d[v] = cur_time
            cur_time += 1
            dfs(v)
    f[u] = cur_time
    cur_time += 1
    return dfs mod = 10**9 + 7 10**9 + 7 mod d = [0 for _ in range(N)] [0 for _ in range(N)] d def I(): return int(sys.stdin.readline()) def I(): return int(sys.stdin.readline()) I DR = [1, -1, 0, 0] [1, -1, 0, 0] DR def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] LI_ N = I() I() N DC = [0, 0, 1, -1] [0, 0, 1, -1] DC visited = [False for _ in range(N)] [False for _ in range(N)] visited edge_list = LI() LI() edge_list inf = 10**20 10**20 inf k = edge_list[0], edge_list[1] edge_list[1] k v_list = edge_list[2:] edge_list[2:] v_list u, k = edge_list[0], edge_list[1] edge_list[0] u
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

N = I()
adj = [[] for _ in range(N)]
visited = [False for _ in range(N)]
d = [0 for _ in range(N)]
f = [0 for _ in range(N)]
cur_time = 1

for _ in range(N):
    edge_list = LI()
    u, k = edge_list[0], edge_list[1]
    if k == 0:
        continue
    v_list = edge_list[2:]
    u -= 1
    for v in v_list:
        v -= 1
        adj[u].append(v)

def dfs(u):
    global cur_time
    visited[u] = True
    for v in adj[u]:
        if not visited[v]:
            d[v] = cur_time
            cur_time += 1
            dfs(v)
    f[u] = cur_time
    cur_time += 1
    return

for v in range(N):
    if not visited[v]:
        d[v] = cur_time
        cur_time += 1
        dfs(v)

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



