def dfs(v):
    global t, d, f, visited
    d[v] = t
    visited[v] = True
    t += 1
    for u in AL[v]:
        if not visited[u]:
            dfs(u)
    f[v] = t
    t += 1

# 入力
n = int(input())
AL = [[] for _ in range(n + 1)]
for v in range(1, n + 1):
    AL[v] = [int(x) for x in input().split()][2:]

# 計算
d = [0] * (n + 1)
f = [0] * (n + 1)
t = 1
visited = [False] * (n + 1)
for v in range(1, n + 1):
    if not visited[v]:
        dfs(v)

# 出力
for v in range(1, n + 1):
    print(v, d[v], f[v])
 def dfs(v):
    global t, d, f, visited
    d[v] = t
    visited[v] = True
    t += 1
    for u in AL[v]:
        if not visited[u]:
            dfs(u)
    f[v] = t
    t += 1

# 入力 dfs global t, d, f, visited d[v] = t d[v] d v t visited[v] = True visited[v] visited v True t += 1 t 1 for u in AL[v]:
        if not visited[u]:
            dfs(u)
     u AL[v] AL v if not visited[u]:
            dfs(u)
     not visited[u] visited[u] visited u dfs(u) dfs u f[v] = t f[v] f v t t += 1 t 1 v v n = int(input()) n int(input()) int input() input [] for _ in range(n + 1) for _ in range(n + 1) _ range(n + 1) range n + 1 n 1 for _ in range(n + 1) [] AL = [[] for _ in range(n + 1)] AL [[] for _ in range(n + 1)] for v in range(1, n + 1):
    AL[v] = [int(x) for x in input().split()][2:]

# 計算 v range(1, n + 1) range 1 n + 1 n 1 int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x AL[v] = [int(x) for x in input().split()][2:] AL[v] AL v [int(x) for x in input().split()][2:] [int(x) for x in input().split()] 2: 2 d = [0] * (n + 1) d [0] * (n + 1) [0] 0 n + 1 n 1 f = [0] * (n + 1) f [0] * (n + 1) [0] 0 n + 1 n 1 t = 1 t 1 visited = [False] * (n + 1) visited [False] * (n + 1) [False] False n + 1 n 1 for v in range(1, n + 1):
    if not visited[v]:
        dfs(v)

# 出力 v range(1, n + 1) range 1 n + 1 n 1 if not visited[v]:
        dfs(v)

# 出力 not visited[v] visited[v] visited v dfs(v) dfs v for v in range(1, n + 1):
    print(v, d[v], f[v]) v range(1, n + 1) range 1 n + 1 n 1 print(v, d[v], f[v]) print v d[v] d v f[v] f v AL = [[] for _ in range(n + 1)] [[] for _ in range(n + 1)] AL n = int(input()) int(input()) n visited = [False] * (n + 1) [False] * (n + 1) visited f = [0] * (n + 1) [0] * (n + 1) f t = 1 1 t d = [0] * (n + 1) [0] * (n + 1) d def dfs(v):
    global t, d, f, visited
    d[v] = t
    visited[v] = True
    t += 1
    for u in AL[v]:
        if not visited[u]:
            dfs(u)
    f[v] = t
    t += 1

# 入力 def dfs(v):
    global t, d, f, visited
    d[v] = t
    visited[v] = True
    t += 1
    for u in AL[v]:
        if not visited[u]:
            dfs(u)
    f[v] = t
    t += 1

# 入力 dfs
def dfs(v):
    global t, d, f, visited
    d[v] = t
    visited[v] = True
    t += 1
    for u in AL[v]:
        if not visited[u]:
            dfs(u)
    f[v] = t
    t += 1

# 入力
n = int(input())
AL = [[] for _ in range(n + 1)]
for v in range(1, n + 1):
    AL[v] = [int(x) for x in input().split()][2:]

# 計算
d = [0] * (n + 1)
f = [0] * (n + 1)
t = 1
visited = [False] * (n + 1)
for v in range(1, n + 1):
    if not visited[v]:
        dfs(v)

# 出力
for v in range(1, n + 1):
    print(v, d[v], f[v])

