# ALDS_11_B - 深さ優先探索
import sys

n = int(input())
e = [None] * n
for _ in range(n):
    u, k, *v = map(int, sys.stdin.readline().strip().split())
    e[u - 1] = [i - 1 for i in v]


S = []  # stack
time = 0
t_in = [0] * n
t_out = [0] * n
fp = [False] * n  # foot print  訪問の記録


def dfs(u):
    global time

    S.append(u)
    time += 1
    t_in[u] = time
    fp[u] = True

    while S:
        u = S[-1]

        v = None
        for i in e[u]:
            if fp[i] is False:
                v = i
                break

        time += 1
        if v is not None:
            S.append(v)
            t_in[v] = time
            fp[v] = True

        else:
            v = S.pop()
            t_out[v] = time


while False in fp:
    dfs(fp.index(False))

for i in range(n):
    print(f'{i + 1} {t_in[i]} {t_out[i]}')
 import sys sys n = int(input()) n int(input()) int input() input e = [None] * n e [None] * n [None] None n for _ in range(n):
    u, k, *v = map(int, sys.stdin.readline().strip().split())
    e[u - 1] = [i - 1 for i in v] _ range(n) range n u, k, *v = map(int, sys.stdin.readline().strip().split()) u map(int, sys.stdin.readline().strip().split()) map int sys.stdin.readline().strip().split() sys.stdin.readline().strip().split sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip split k *v v i - 1 for i in v for i in v i v for i in v i - 1 i 1 e[u - 1] = [i - 1 for i in v] e[u - 1] e u - 1 u 1 [i - 1 for i in v] S = [] S [] time = 0 time 0 t_in = [0] * n t_in [0] * n [0] 0 n t_out = [0] * n t_out [0] * n [0] 0 n fp = [False] * n fp [False] * n [False] False n def dfs(u):
    global time

    S.append(u)
    time += 1
    t_in[u] = time
    fp[u] = True

    while S:
        u = S[-1]

        v = None
        for i in e[u]:
            if fp[i] is False:
                v = i
                break

        time += 1
        if v is not None:
            S.append(v)
            t_in[v] = time
            fp[v] = True

        else:
            v = S.pop()
            t_out[v] = time dfs global time S.append(u) S.append S append u time += 1 time 1 t_in[u] = time t_in[u] t_in u time fp[u] = True fp[u] fp u True while S:
        u = S[-1]

        v = None
        for i in e[u]:
            if fp[i] is False:
                v = i
                break

        time += 1
        if v is not None:
            S.append(v)
            t_in[v] = time
            fp[v] = True

        else:
            v = S.pop()
            t_out[v] = time S u = S[-1] u S[-1] S -1 v = None v None for i in e[u]:
            if fp[i] is False:
                v = i
                break

         i e[u] e u if fp[i] is False:
                v = i
                break

         fp[i] is False fp[i] fp i False v = i v i break time += 1 time 1 if v is not None:
            S.append(v)
            t_in[v] = time
            fp[v] = True

        else:
            v = S.pop()
            t_out[v] = time v is not None v None S.append(v) S.append S append v t_in[v] = time t_in[v] t_in v time fp[v] = True fp[v] fp v True v = S.pop() v S.pop() S.pop S pop t_out[v] = time t_out[v] t_out v time u u while False in fp:
    dfs(fp.index(False)) False in fp False fp dfs(fp.index(False)) dfs fp.index(False) fp.index fp index False for i in range(n):
    print(f'{i + 1} {t_in[i]} {t_out[i]}') i range(n) range n print(f'{i + 1} {t_in[i]} {t_out[i]}') print f'{i + 1} {t_in[i]} {t_out[i]}' e = [None] * n [None] * n e n = int(input()) int(input()) n fp = [False] * n [False] * n fp t_out = [0] * n [0] * n t_out time = 0 0 time def dfs(u):
    global time

    S.append(u)
    time += 1
    t_in[u] = time
    fp[u] = True

    while S:
        u = S[-1]

        v = None
        for i in e[u]:
            if fp[i] is False:
                v = i
                break

        time += 1
        if v is not None:
            S.append(v)
            t_in[v] = time
            fp[v] = True

        else:
            v = S.pop()
            t_out[v] = time def dfs(u):
    global time

    S.append(u)
    time += 1
    t_in[u] = time
    fp[u] = True

    while S:
        u = S[-1]

        v = None
        for i in e[u]:
            if fp[i] is False:
                v = i
                break

        time += 1
        if v is not None:
            S.append(v)
            t_in[v] = time
            fp[v] = True

        else:
            v = S.pop()
            t_out[v] = time dfs k, *v = map(int, sys.stdin.readline().strip().split()) map(int, sys.stdin.readline().strip().split()) k S = [] [] S u, k, *v = map(int, sys.stdin.readline().strip().split()) map(int, sys.stdin.readline().strip().split()) u t_in = [0] * n [0] * n t_in
# ALDS_11_B - 深さ優先探索
import sys

n = int(input())
e = [None] * n
for _ in range(n):
    u, k, *v = map(int, sys.stdin.readline().strip().split())
    e[u - 1] = [i - 1 for i in v]


S = []  # stack
time = 0
t_in = [0] * n
t_out = [0] * n
fp = [False] * n  # foot print  訪問の記録


def dfs(u):
    global time

    S.append(u)
    time += 1
    t_in[u] = time
    fp[u] = True

    while S:
        u = S[-1]

        v = None
        for i in e[u]:
            if fp[i] is False:
                v = i
                break

        time += 1
        if v is not None:
            S.append(v)
            t_in[v] = time
            fp[v] = True

        else:
            v = S.pop()
            t_out[v] = time


while False in fp:
    dfs(fp.index(False))

for i in range(n):
    print(f'{i + 1} {t_in[i]} {t_out[i]}')

