def dfs(v, u=0):
    global n, t, d, f, reached
    if len(reached) == n:
        return

    d[u] = t
    t += 1

    reached.add(u + 1)
    for ui in range(v[u][1]):
        next = v[u][2 + ui]
        if next in reached:
            continue
        dfs(v, next - 1)

    f[u] = t
    t += 1


n = int(input())
v = []
for _ in range(n):
    v.append(list(map(int, input().split())))

t = 1
d = [0] * n
f = [0] * n
reached = set()


for ui in range(n):
    if ui + 1 not in reached:
        dfs(v, ui)

for ui in range(n):
    print('%d %d %d' % (ui + 1, d[ui], f[ui])) def dfs(v, u=0):
    global n, t, d, f, reached
    if len(reached) == n:
        return

    d[u] = t
    t += 1

    reached.add(u + 1)
    for ui in range(v[u][1]):
        next = v[u][2 + ui]
        if next in reached:
            continue
        dfs(v, next - 1)

    f[u] = t
    t += 1 dfs global n, t, d, f, reached if len(reached) == n:
        return

     len(reached) == n len(reached) len reached n return d[u] = t d[u] d u t t += 1 t 1 reached.add(u + 1) reached.add reached add u + 1 u 1 for ui in range(v[u][1]):
        next = v[u][2 + ui]
        if next in reached:
            continue
        dfs(v, next - 1)

     ui range(v[u][1]) range v[u][1] [u] v u 1 next = v[u][2 + ui] next v[u][2 + ui] [u] v u 2 + ui 2 ui if next in reached:
            continue
         next in reached next reached continue dfs(v, next - 1) dfs v next - 1 next 1 f[u] = t f[u] f u t t += 1 t 1 v v u=0 u 0 n = int(input()) n int(input()) int input() input v = [] v [] for _ in range(n):
    v.append(list(map(int, input().split()))) _ range(n) range n v.append(list(map(int, input().split()))) v.append v append list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split t = 1 t 1 d = [0] * n d [0] * n [0] 0 n f = [0] * n f [0] * n [0] 0 n reached = set() reached set() set for ui in range(n):
    if ui + 1 not in reached:
        dfs(v, ui) ui range(n) range n if ui + 1 not in reached:
        dfs(v, ui) ui + 1 not in reached ui + 1 ui 1 reached dfs(v, ui) dfs v ui for ui in range(n):
    print('%d %d %d' % (ui + 1, d[ui], f[ui])) ui range(n) range n print('%d %d %d' % (ui + 1, d[ui], f[ui])) print '%d %d %d' % (ui + 1, d[ui], f[ui]) '%d %d %d' (ui + 1, d[ui], f[ui]) ui + 1 ui 1 d[ui] d ui f[ui] f ui v = [] [] v n = int(input()) int(input()) n f = [0] * n [0] * n f reached = set() set() reached def dfs(v, u=0):
    global n, t, d, f, reached
    if len(reached) == n:
        return

    d[u] = t
    t += 1

    reached.add(u + 1)
    for ui in range(v[u][1]):
        next = v[u][2 + ui]
        if next in reached:
            continue
        dfs(v, next - 1)

    f[u] = t
    t += 1 def dfs(v, u=0):
    global n, t, d, f, reached
    if len(reached) == n:
        return

    d[u] = t
    t += 1

    reached.add(u + 1)
    for ui in range(v[u][1]):
        next = v[u][2 + ui]
        if next in reached:
            continue
        dfs(v, next - 1)

    f[u] = t
    t += 1 dfs t = 1 1 t d = [0] * n [0] * n d
def dfs(v, u=0):
    global n, t, d, f, reached
    if len(reached) == n:
        return

    d[u] = t
    t += 1

    reached.add(u + 1)
    for ui in range(v[u][1]):
        next = v[u][2 + ui]
        if next in reached:
            continue
        dfs(v, next - 1)

    f[u] = t
    t += 1


n = int(input())
v = []
for _ in range(n):
    v.append(list(map(int, input().split())))

t = 1
d = [0] * n
f = [0] * n
reached = set()


for ui in range(n):
    if ui + 1 not in reached:
        dfs(v, ui)

for ui in range(n):
    print('%d %d %d' % (ui + 1, d[ui], f[ui]))
