# -*- coding: utf-8 -*-
# 標準入力を取得
n = int(input())
G = {}
for _ in range(n):
    g = list(map(int, input().split()))
    G[g[0]] = g[2:]

# 求解処理
seen = [False for _ in range(n)]
ans = []


def dfs(v: int) -> None:
    seen[v - 1] = True
    ans.append(v)

    for w in G[v]:
        if not seen[w - 1]:
            dfs(w)

    ans.append(v)


while sum(seen) != n:
    v = seen.index(False)
    dfs(v + 1)

d = [-1 for _ in range(n)]
f = [-1 for _ in range(n)]

for i, a in enumerate(ans):
    if d[a - 1] == -1:
        d[a - 1] = i + 1
    else:
        f[a - 1] = i + 1

for id in range(n):
    print(id + 1, d[id], f[id])
 n = int(input()) n int(input()) int input() input G = {} G {} for _ in range(n):
    g = list(map(int, input().split()))
    G[g[0]] = g[2:]

# 求解処理 _ range(n) range n g = list(map(int, input().split())) g list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split G[g[0]] = g[2:] G[g[0]] G g[0] g 0 g[2:] g 2: 2 False for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) False seen = [False for _ in range(n)] seen [False for _ in range(n)] ans = [] ans [] def dfs(v: int) -> None:
    seen[v - 1] = True
    ans.append(v)

    for w in G[v]:
        if not seen[w - 1]:
            dfs(w)

    ans.append(v) dfs seen[v - 1] = True seen[v - 1] seen v - 1 v 1 True ans.append(v) ans.append ans append v for w in G[v]:
        if not seen[w - 1]:
            dfs(w)

     w G[v] G v if not seen[w - 1]:
            dfs(w)

     not seen[w - 1] seen[w - 1] seen w - 1 w 1 dfs(w) dfs w ans.append(v) ans.append ans append v v: int v while sum(seen) != n:
    v = seen.index(False)
    dfs(v + 1) sum(seen) != n sum(seen) sum seen n v = seen.index(False) v seen.index(False) seen.index seen index False dfs(v + 1) dfs v + 1 v 1 -1 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) -1 d = [-1 for _ in range(n)] d [-1 for _ in range(n)] -1 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) -1 f = [-1 for _ in range(n)] f [-1 for _ in range(n)] for i, a in enumerate(ans):
    if d[a - 1] == -1:
        d[a - 1] = i + 1
    else:
        f[a - 1] = i + 1 i a enumerate(ans) enumerate ans if d[a - 1] == -1:
        d[a - 1] = i + 1
    else:
        f[a - 1] = i + 1 d[a - 1] == -1 d[a - 1] d a - 1 a 1 -1 d[a - 1] = i + 1 d[a - 1] d a - 1 a 1 i + 1 i 1 f[a - 1] = i + 1 f[a - 1] f a - 1 a 1 i + 1 i 1 for id in range(n):
    print(id + 1, d[id], f[id]) id range(n) range n print(id + 1, d[id], f[id]) print id + 1 id 1 d[id] d id f[id] f id v = seen.index(False) seen.index(False) v f = [-1 for _ in range(n)] [-1 for _ in range(n)] f d = [-1 for _ in range(n)] [-1 for _ in range(n)] d g = list(map(int, input().split())) list(map(int, input().split())) g G = {} {} G n = int(input()) int(input()) n seen = [False for _ in range(n)] [False for _ in range(n)] seen ans = [] [] ans def dfs(v: int) -> None:
    seen[v - 1] = True
    ans.append(v)

    for w in G[v]:
        if not seen[w - 1]:
            dfs(w)

    ans.append(v) def dfs(v: int) -> None:
    seen[v - 1] = True
    ans.append(v)

    for w in G[v]:
        if not seen[w - 1]:
            dfs(w)

    ans.append(v) dfs
# -*- coding: utf-8 -*-
# 標準入力を取得
n = int(input())
G = {}
for _ in range(n):
    g = list(map(int, input().split()))
    G[g[0]] = g[2:]

# 求解処理
seen = [False for _ in range(n)]
ans = []


def dfs(v: int) -> None:
    seen[v - 1] = True
    ans.append(v)

    for w in G[v]:
        if not seen[w - 1]:
            dfs(w)

    ans.append(v)


while sum(seen) != n:
    v = seen.index(False)
    dfs(v + 1)

d = [-1 for _ in range(n)]
f = [-1 for _ in range(n)]

for i, a in enumerate(ans):
    if d[a - 1] == -1:
        d[a - 1] = i + 1
    else:
        f[a - 1] = i + 1

for id in range(n):
    print(id + 1, d[id], f[id])

