from sys import stdin

n = int(stdin.readline())

M = [list(map(int, stdin.readline().split()[2:])) for i in range(n)]

sndf = [[False, i] for i in range(1, n + 1)]

tt = 0

def dfs(u):

    global tt

    sndf[u][0] = True

    tt += 1

    sndf[u].append(tt)

    for v in M[u]:

        v -= 1

        if not sndf[v][0]:

            dfs(v)

    tt += 1

    sndf[u].append(tt)

for i in range(0, n):

    if not sndf[i][0]:

        dfs(i)

    print((*sndf[i][1:]))
def MAIN():

    n = int(eval(input()))

    ans = [[i, 0, 0] for i in range((n + 1))]

    G = [[] for _ in range((n + 1))]

    for _ in range(n):

        u, k, *v = list(map(int, input().split()))

        G[u] = v

    cnt = 1

    def dfs(u):

        nonlocal ans

        if ans[u][1] != 0:

            return

        nonlocal cnt

        ans[u][1] = cnt

        cnt += 1

        for v in G[u]:

            dfs(v)

        ans[u][2] = cnt

        cnt += 1

    for i in range(1, n + 1):

        if ans[i][1] == 0:

            dfs(i)

    for i in range(1, n + 1):

        print((" ".join(map(str, ans[i]))))

MAIN()



from sys import stdin

n = int(stdin.readline())
M = [list(map(int, stdin.readline().split()[2:])) for i in range(n)]
sndf = [[False, i] for i in range(1, n + 1)]
tt = 0


def dfs(u):
    global tt
    sndf[u][0] = True
    tt += 1
    sndf[u].append(tt)
    for v in M[u]:
        v -= 1
        if not sndf[v][0]:
            dfs(v)
    tt += 1
    sndf[u].append(tt)


for i in range(0, n):
    if not sndf[i][0]:
        dfs(i)
    print((*sndf[i][1:]))

def MAIN():
    n = int(eval(input()))
    ans = [[i, 0, 0] for i in range((n + 1))]
    G = [[] for _ in range((n + 1))]
    for _ in range(n):
        u, k, *v = list(map(int, input().split()))
        G[u] = v
    cnt = 1

    def dfs(u):
        nonlocal ans
        if ans[u][1] != 0:
            return
        nonlocal cnt
        ans[u][1] = cnt
        cnt += 1
        for v in G[u]:
            dfs(v)
        ans[u][2] = cnt
        cnt += 1

    for i in range(1, n + 1):
        if ans[i][1] == 0:
            dfs(i)
    for i in range(1, n + 1):
        print((" ".join(map(str, ans[i]))))


MAIN()

-from sys import stdin +def MAIN(): +    n = int(eval(input())) +    ans = [[i, 0, 0] for i in range((n + 1))] +    G = [[] for _ in range((n + 1))] +    for _ in range(n): +        u, k, *v = list(map(int, input().split())) +        G[u] = v +    cnt = 1 -n = int(stdin.readline()) -M = [list(map(int, stdin.readline().split()[2:])) for i in range(n)] -sndf = [[False, i] for i in range(1, n + 1)] -tt = 0 +    def dfs(u): +        nonlocal ans +        if ans[u][1] != 0: +            return +        nonlocal cnt +        ans[u][1] = cnt +        cnt += 1 +        for v in G[u]: +            dfs(v) +        ans[u][2] = cnt +        cnt += 1 + +    for i in range(1, n + 1): +        if ans[i][1] == 0: +            dfs(i) +    for i in range(1, n + 1): +        print((" ".join(map(str, ans[i])))) -def dfs(u): -    global tt -    sndf[u][0] = True -    tt += 1 -    sndf[u].append(tt) -    for v in M[u]: -        v -= 1 -        if not sndf[v][0]: -            dfs(v) -    tt += 1 -    sndf[u].append(tt) - - -for i in range(0, n): -    if not sndf[i][0]: -        dfs(i) -    print((*sndf[i][1:])) +MAIN()