cin = open(0).read().strip().split('\n')
n = int(cin[0])
g = [list(map(lambda x: int(x)-1, a.split(' ')[2:])) for a in cin[1:]]

first_order = [-1] * n
last_order = [-1] * n
ptr = 1

def dfs(g, seen, idx):
    global first_order, first_order, ptr

    first_order[idx] = ptr
    ptr += 1

    seen[idx] = True
    for i in g[idx]:
        # idxから行ける各頂点について
        if seen[i]: continue
        dfs(g, seen, i)

    last_order[idx] = ptr
    ptr += 1

seen = [False] * n
dfs(g, seen, 0)

# 孤立している頂点対策
for i in range(n):
    if not seen[i]:
        ans = dfs(g, seen, i)

# 出力
for idx, (f, l) in enumerate(zip(first_order, last_order)):
    print(idx+1, f, l) cin = open(0).read().strip().split('\n') cin open(0).read().strip().split('\n') (0).read().strip().split (0).read().strip() (0).read().strip (0).read() (0).read (0) open 0 read strip split '\n' n = int(cin[0]) n int(cin[0]) int cin[0] cin 0 list(map(lambda x: int(x)-1, a.split(' ')[2:])) for a in cin[1:] for a in cin[1:] a cin[1:] cin 1: 1 for a in cin[1:] list(map(lambda x: int(x)-1, a.split(' ')[2:])) list map(lambda x: int(x)-1, a.split(' ')[2:]) map lambda x: int(x)-1 int(x)-1 int(x) int x 1 x a.split(' ')[2:] a.split(' ') a.split a split ' ' 2: 2 g = [list(map(lambda x: int(x)-1, a.split(' ')[2:])) for a in cin[1:]] g [list(map(lambda x: int(x)-1, a.split(' ')[2:])) for a in cin[1:]] first_order = [-1] * n first_order [-1] * n [-1] -1 n last_order = [-1] * n last_order [-1] * n [-1] -1 n ptr = 1 ptr 1 def dfs(g, seen, idx):
    global first_order, first_order, ptr

    first_order[idx] = ptr
    ptr += 1

    seen[idx] = True
    for i in g[idx]:
        # idxから行ける各頂点について
        if seen[i]: continue
        dfs(g, seen, i)

    last_order[idx] = ptr
    ptr += 1 dfs global first_order, first_order, ptr first_order[idx] = ptr first_order[idx] first_order idx ptr ptr += 1 ptr 1 seen[idx] = True seen[idx] seen idx True for i in g[idx]:
        # idxから行ける各頂点について
        if seen[i]: continue
        dfs(g, seen, i)

     i g[idx] g idx if seen[i]: continue
         seen[i] seen i dfs(g, seen, i) dfs g seen i last_order[idx] = ptr last_order[idx] last_order idx ptr ptr += 1 ptr 1 g g seen seen idx idx seen = [False] * n seen [False] * n [False] False n dfs(g, seen, 0) dfs g seen 0 for i in range(n):
    if not seen[i]:
        ans = dfs(g, seen, i)

# 出力 i range(n) range n if not seen[i]:
        ans = dfs(g, seen, i)

# 出力 not seen[i] seen[i] seen i ans = dfs(g, seen, i) ans dfs(g, seen, i) dfs g seen i for idx, (f, l) in enumerate(zip(first_order, last_order)):
    print(idx+1, f, l) idx (f, l) f l enumerate(zip(first_order, last_order)) enumerate zip(first_order, last_order) zip first_order last_order print(idx+1, f, l) print idx+1 idx 1 f l seen = [False] * n [False] * n seen g = [list(map(lambda x: int(x)-1, a.split(' ')[2:])) for a in cin[1:]] [list(map(lambda x: int(x)-1, a.split(' ')[2:])) for a in cin[1:]] g first_order = [-1] * n [-1] * n first_order n = int(cin[0]) int(cin[0]) n last_order = [-1] * n [-1] * n last_order cin = open(0).read().strip().split('\n') open(0).read().strip().split('\n') cin def dfs(g, seen, idx):
    global first_order, first_order, ptr

    first_order[idx] = ptr
    ptr += 1

    seen[idx] = True
    for i in g[idx]:
        # idxから行ける各頂点について
        if seen[i]: continue
        dfs(g, seen, i)

    last_order[idx] = ptr
    ptr += 1 def dfs(g, seen, idx):
    global first_order, first_order, ptr

    first_order[idx] = ptr
    ptr += 1

    seen[idx] = True
    for i in g[idx]:
        # idxから行ける各頂点について
        if seen[i]: continue
        dfs(g, seen, i)

    last_order[idx] = ptr
    ptr += 1 dfs ans = dfs(g, seen, i) dfs(g, seen, i) ans ptr = 1 1 ptr
cin = open(0).read().strip().split('\n')
n = int(cin[0])
g = [list(map(lambda x: int(x)-1, a.split(' ')[2:])) for a in cin[1:]]

first_order = [-1] * n
last_order = [-1] * n
ptr = 1

def dfs(g, seen, idx):
    global first_order, first_order, ptr

    first_order[idx] = ptr
    ptr += 1

    seen[idx] = True
    for i in g[idx]:
        # idxから行ける各頂点について
        if seen[i]: continue
        dfs(g, seen, i)

    last_order[idx] = ptr
    ptr += 1

seen = [False] * n
dfs(g, seen, 0)

# 孤立している頂点対策
for i in range(n):
    if not seen[i]:
        ans = dfs(g, seen, i)

# 出力
for idx, (f, l) in enumerate(zip(first_order, last_order)):
    print(idx+1, f, l)
