
def dfs_visit(u):
    global n, M, d, f, time

    if color[u] == 'WHITE':
        color[u] = 'GRAY'
        time += 1
        d[u] = time

        for v in range(n):
            if M[u][v] == 0:
                continue
            if color[v] == 'WHITE':
                dfs_visit(v)

        color[u] = 'BLACK'
        time += 1
        f[u] = time


def dfs():
    global n, M, d, f, time

    for u in range(n):
        if color[u] == 'WHITE':  # 連結グラフとは限らないため。
            dfs_visit(u)

    for u in range(n):
        print('{} {} {}'.format(u+1, d[u], f[u]))


n = int(input())

M = [[0 for i in range(n)] for j in range(n)]
color = ['WHITE'] * n  # 各頂点の色を記録。ホワイト（未探索）、グレイ（探索中）、ブラック（探索ずみ）
d = [None] * n  # vを最初に発見した時間
f = [None] * n  # vの完了時刻
time = 0

for i in range(n):
    _ = list(map(int, input().split()))
    u = _[0] - 1  # 0オリジンに変換

    degree = _[1]
    for j in range(degree):
        v = _[j+2] - 1  # 0オリジンに変換
        M[u][v] = 1

# for row in M:
#     print(' '.join(map(str, row)))

dfs()
 def dfs_visit(u):
    global n, M, d, f, time

    if color[u] == 'WHITE':
        color[u] = 'GRAY'
        time += 1
        d[u] = time

        for v in range(n):
            if M[u][v] == 0:
                continue
            if color[v] == 'WHITE':
                dfs_visit(v)

        color[u] = 'BLACK'
        time += 1
        f[u] = time dfs_visit global n, M, d, f, time if color[u] == 'WHITE':
        color[u] = 'GRAY'
        time += 1
        d[u] = time

        for v in range(n):
            if M[u][v] == 0:
                continue
            if color[v] == 'WHITE':
                dfs_visit(v)

        color[u] = 'BLACK'
        time += 1
        f[u] = time color[u] == 'WHITE' color[u] color u 'WHITE' color[u] = 'GRAY' color[u] color u 'GRAY' time += 1 time 1 d[u] = time d[u] d u time for v in range(n):
            if M[u][v] == 0:
                continue
            if color[v] == 'WHITE':
                dfs_visit(v)

         v range(n) range n if M[u][v] == 0:
                continue
             M[u][v] == 0 M[u][v] [u] M u v 0 continue if color[v] == 'WHITE':
                dfs_visit(v)

         color[v] == 'WHITE' color[v] color v 'WHITE' dfs_visit(v) dfs_visit v color[u] = 'BLACK' color[u] color u 'BLACK' time += 1 time 1 f[u] = time f[u] f u time u u def dfs():
    global n, M, d, f, time

    for u in range(n):
        if color[u] == 'WHITE':  # 連結グラフとは限らないため。
            dfs_visit(u)

    for u in range(n):
        print('{} {} {}'.format(u+1, d[u], f[u])) dfs global n, M, d, f, time for u in range(n):
        if color[u] == 'WHITE':  # 連結グラフとは限らないため。
            dfs_visit(u)

     u range(n) range n if color[u] == 'WHITE':  # 連結グラフとは限らないため。
            dfs_visit(u)

     color[u] == 'WHITE' color[u] color u 'WHITE' dfs_visit(u) dfs_visit u for u in range(n):
        print('{} {} {}'.format(u+1, d[u], f[u])) u range(n) range n print('{} {} {}'.format(u+1, d[u], f[u])) print '{} {} {}'.format(u+1, d[u], f[u]) '{} {} {}'.format '{} {} {}' format u+1 u 1 d[u] d u f[u] f u n = int(input()) n int(input()) int input() input [0 for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [0 for i in range(n)] M = [[0 for i in range(n)] for j in range(n)] M [[0 for i in range(n)] for j in range(n)] color = ['WHITE'] * n color ['WHITE'] * n ['WHITE'] 'WHITE' n d = [None] * n d [None] * n [None] None n f = [None] * n f [None] * n [None] None n time = 0 time 0 for i in range(n):
    _ = list(map(int, input().split()))
    u = _[0] - 1  # 0オリジンに変換

    degree = _[1]
    for j in range(degree):
        v = _[j+2] - 1  # 0オリジンに変換
        M[u][v] = 1

# for row in M:
#     print(' '.join(map(str, row))) i range(n) range n _ = list(map(int, input().split())) _ list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split u = _[0] - 1 u _[0] - 1 _[0] _ 0 1 degree = _[1] degree _[1] _ 1 for j in range(degree):
        v = _[j+2] - 1  # 0オリジンに変換
        M[u][v] = 1

# for row in M:
#     print(' '.join(map(str, row))) j range(degree) range degree v = _[j+2] - 1 v _[j+2] - 1 _[j+2] _ j+2 j 2 1 M[u][v] = 1 M[u][v] [u] M u v 1 dfs() dfs u = _[0] - 1 _[0] - 1 u def dfs():
    global n, M, d, f, time

    for u in range(n):
        if color[u] == 'WHITE':  # 連結グラフとは限らないため。
            dfs_visit(u)

    for u in range(n):
        print('{} {} {}'.format(u+1, d[u], f[u])) def dfs():
    global n, M, d, f, time

    for u in range(n):
        if color[u] == 'WHITE':  # 連結グラフとは限らないため。
            dfs_visit(u)

    for u in range(n):
        print('{} {} {}'.format(u+1, d[u], f[u])) dfs degree = _[1] _[1] degree v = _[j+2] - 1 _[j+2] - 1 v color = ['WHITE'] * n ['WHITE'] * n color time = 0 0 time M = [[0 for i in range(n)] for j in range(n)] [[0 for i in range(n)] for j in range(n)] M f = [None] * n [None] * n f def dfs_visit(u):
    global n, M, d, f, time

    if color[u] == 'WHITE':
        color[u] = 'GRAY'
        time += 1
        d[u] = time

        for v in range(n):
            if M[u][v] == 0:
                continue
            if color[v] == 'WHITE':
                dfs_visit(v)

        color[u] = 'BLACK'
        time += 1
        f[u] = time def dfs_visit(u):
    global n, M, d, f, time

    if color[u] == 'WHITE':
        color[u] = 'GRAY'
        time += 1
        d[u] = time

        for v in range(n):
            if M[u][v] == 0:
                continue
            if color[v] == 'WHITE':
                dfs_visit(v)

        color[u] = 'BLACK'
        time += 1
        f[u] = time dfs_visit d = [None] * n [None] * n d _ = list(map(int, input().split())) list(map(int, input().split())) _ n = int(input()) int(input()) n

def dfs_visit(u):
    global n, M, d, f, time

    if color[u] == 'WHITE':
        color[u] = 'GRAY'
        time += 1
        d[u] = time

        for v in range(n):
            if M[u][v] == 0:
                continue
            if color[v] == 'WHITE':
                dfs_visit(v)

        color[u] = 'BLACK'
        time += 1
        f[u] = time


def dfs():
    global n, M, d, f, time

    for u in range(n):
        if color[u] == 'WHITE':  # 連結グラフとは限らないため。
            dfs_visit(u)

    for u in range(n):
        print('{} {} {}'.format(u+1, d[u], f[u]))


n = int(input())

M = [[0 for i in range(n)] for j in range(n)]
color = ['WHITE'] * n  # 各頂点の色を記録。ホワイト（未探索）、グレイ（探索中）、ブラック（探索ずみ）
d = [None] * n  # vを最初に発見した時間
f = [None] * n  # vの完了時刻
time = 0

for i in range(n):
    _ = list(map(int, input().split()))
    u = _[0] - 1  # 0オリジンに変換

    degree = _[1]
    for j in range(degree):
        v = _[j+2] - 1  # 0オリジンに変換
        M[u][v] = 1

# for row in M:
#     print(' '.join(map(str, row)))

dfs()

