n = int(input())
g = [None] * n
visited = [0] * n
root = set(range(n))
ts = [[0, 0] for _ in range(n)]
t = 0

while n:
    l = list(map(int, input().split()))
    connected = [i - 1 for i in l[2:]]
    g[l[0] - 1] = [i - 1 for i in l[2:]]
    root -= set(connected)
    n -= 1


def dfs(i):
    global g, t, ts, visited
    lts = ts[i]
    t += 1
    lts[0] = t
    visited[i] = 1
    for c in g[i]:
        if not visited[c]:
            dfs(c)
    t += 1
    lts[1] = t

if root:
    for r in sorted(root):
        dfs(r)
else:
    dfs(0)

for i, v in enumerate(ts):
    print(i + 1, *v) n = int(input()) n int(input()) int input() input g = [None] * n g [None] * n [None] None n visited = [0] * n visited [0] * n [0] 0 n root = set(range(n)) root set(range(n)) set range(n) range n [0, 0] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0, 0] 0 0 ts = [[0, 0] for _ in range(n)] ts [[0, 0] for _ in range(n)] t = 0 t 0 while n:
    l = list(map(int, input().split()))
    connected = [i - 1 for i in l[2:]]
    g[l[0] - 1] = [i - 1 for i in l[2:]]
    root -= set(connected)
    n -= 1 n l = list(map(int, input().split())) l list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split i - 1 for i in l[2:] for i in l[2:] i l[2:] l 2: 2 for i in l[2:] i - 1 i 1 connected = [i - 1 for i in l[2:]] connected [i - 1 for i in l[2:]] i - 1 for i in l[2:] for i in l[2:] i l[2:] l 2: 2 for i in l[2:] i - 1 i 1 g[l[0] - 1] = [i - 1 for i in l[2:]] g[l[0] - 1] g l[0] - 1 l[0] l 0 1 [i - 1 for i in l[2:]] root -= set(connected) root set(connected) set connected n -= 1 n 1 def dfs(i):
    global g, t, ts, visited
    lts = ts[i]
    t += 1
    lts[0] = t
    visited[i] = 1
    for c in g[i]:
        if not visited[c]:
            dfs(c)
    t += 1
    lts[1] = t dfs global g, t, ts, visited lts = ts[i] lts ts[i] ts i t += 1 t 1 lts[0] = t lts[0] lts 0 t visited[i] = 1 visited[i] visited i 1 for c in g[i]:
        if not visited[c]:
            dfs(c)
     c g[i] g i if not visited[c]:
            dfs(c)
     not visited[c] visited[c] visited c dfs(c) dfs c t += 1 t 1 lts[1] = t lts[1] lts 1 t i i if root:
    for r in sorted(root):
        dfs(r)
else:
    dfs(0) root for r in sorted(root):
        dfs(r) r sorted(root) sorted root dfs(r) dfs r dfs(0) dfs 0 for i, v in enumerate(ts):
    print(i + 1, *v) i v enumerate(ts) enumerate ts print(i + 1, *v) print i + 1 i 1 *v v n -= 1 1 n def dfs(i):
    global g, t, ts, visited
    lts = ts[i]
    t += 1
    lts[0] = t
    visited[i] = 1
    for c in g[i]:
        if not visited[c]:
            dfs(c)
    t += 1
    lts[1] = t def dfs(i):
    global g, t, ts, visited
    lts = ts[i]
    t += 1
    lts[0] = t
    visited[i] = 1
    for c in g[i]:
        if not visited[c]:
            dfs(c)
    t += 1
    lts[1] = t dfs n = int(input()) int(input()) n root -= set(connected) set(connected) root root = set(range(n)) set(range(n)) root connected = [i - 1 for i in l[2:]] [i - 1 for i in l[2:]] connected l = list(map(int, input().split())) list(map(int, input().split())) l t = 0 0 t g = [None] * n [None] * n g visited = [0] * n [0] * n visited ts = [[0, 0] for _ in range(n)] [[0, 0] for _ in range(n)] ts
n = int(input())
g = [None] * n
visited = [0] * n
root = set(range(n))
ts = [[0, 0] for _ in range(n)]
t = 0

while n:
    l = list(map(int, input().split()))
    connected = [i - 1 for i in l[2:]]
    g[l[0] - 1] = [i - 1 for i in l[2:]]
    root -= set(connected)
    n -= 1


def dfs(i):
    global g, t, ts, visited
    lts = ts[i]
    t += 1
    lts[0] = t
    visited[i] = 1
    for c in g[i]:
        if not visited[c]:
            dfs(c)
    t += 1
    lts[1] = t

if root:
    for r in sorted(root):
        dfs(r)
else:
    dfs(0)

for i, v in enumerate(ts):
    print(i + 1, *v)