N = int(input())
M = []
for i in range(N):
    a = list(map(int,input().strip().split()))
    b = [int(i+1 in a[2:]) for i in range(N)]
    M.append(b)

time = 1
D = [-1 for _ in range(N)]
F = [-1 for _ in range(N)]
def dfs(src):
    global time # 関数内でglobal変数の書き換えることを宣言
    D[src] = time # 訪問時刻を記録
    time += 1
    for dst in range(N):
        # srcからdstに移動可能で、dstが未訪問だったら
        if M[src][dst] == 1 and D[dst] == -1:
            dfs(dst)
    F[src] = time # 訪問終了時刻を記録
    time += 1
    # 関数の終わりで親に戻る(青矢印)

for root in range(N):
    # 番号が若い節点から
    if D[root] == -1:
        # D[root]が未訪問だったら
        dfs(root) # dfsを始める

[print(i+1, D[i], F[i]) for i in range(N)]
 N = int(input()) N int(input()) int input() input M = [] M [] for i in range(N):
    a = list(map(int,input().strip().split()))
    b = [int(i+1 in a[2:]) for i in range(N)]
    M.append(b) i range(N) range N a = list(map(int,input().strip().split())) a list(map(int,input().strip().split())) list map(int,input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split int(i+1 in a[2:]) for i in range(N) for i in range(N) i range(N) range N for i in range(N) int(i+1 in a[2:]) int i+1 in a[2:] i+1 i 1 a[2:] a 2: 2 b = [int(i+1 in a[2:]) for i in range(N)] b [int(i+1 in a[2:]) for i in range(N)] M.append(b) M.append M append b time = 1 time 1 -1 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) -1 D = [-1 for _ in range(N)] D [-1 for _ in range(N)] -1 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) -1 F = [-1 for _ in range(N)] F [-1 for _ in range(N)] def dfs(src):
    global time # 関数内でglobal変数の書き換えることを宣言
    D[src] = time # 訪問時刻を記録
    time += 1
    for dst in range(N):
        # srcからdstに移動可能で、dstが未訪問だったら
        if M[src][dst] == 1 and D[dst] == -1:
            dfs(dst)
    F[src] = time # 訪問終了時刻を記録
    time += 1
    # 関数の終わりで親に戻る(青矢印) dfs global time D[src] = time D[src] D src time time += 1 time 1 for dst in range(N):
        # srcからdstに移動可能で、dstが未訪問だったら
        if M[src][dst] == 1 and D[dst] == -1:
            dfs(dst)
     dst range(N) range N if M[src][dst] == 1 and D[dst] == -1:
            dfs(dst)
     M[src][dst] == 1 and D[dst] == -1 M[src][dst] == 1 M[src][dst] [src] M src dst 1 D[dst] == -1 D[dst] D dst -1 dfs(dst) dfs dst F[src] = time F[src] F src time time += 1 time 1 src src for root in range(N):
    # 番号が若い節点から
    if D[root] == -1:
        # D[root]が未訪問だったら
        dfs(root) # dfsを始める root range(N) range N if D[root] == -1:
        # D[root]が未訪問だったら
        dfs(root) # dfsを始める D[root] == -1 D[root] D root -1 dfs(root) dfs root print(i+1, D[i], F[i]) for i in range(N) for i in range(N) i range(N) range N for i in range(N) print(i+1, D[i], F[i]) print i+1 i 1 D[i] D i F[i] F i [print(i+1, D[i], F[i]) for i in range(N)] a = list(map(int,input().strip().split())) list(map(int,input().strip().split())) a D = [-1 for _ in range(N)] [-1 for _ in range(N)] D def dfs(src):
    global time # 関数内でglobal変数の書き換えることを宣言
    D[src] = time # 訪問時刻を記録
    time += 1
    for dst in range(N):
        # srcからdstに移動可能で、dstが未訪問だったら
        if M[src][dst] == 1 and D[dst] == -1:
            dfs(dst)
    F[src] = time # 訪問終了時刻を記録
    time += 1
    # 関数の終わりで親に戻る(青矢印) def dfs(src):
    global time # 関数内でglobal変数の書き換えることを宣言
    D[src] = time # 訪問時刻を記録
    time += 1
    for dst in range(N):
        # srcからdstに移動可能で、dstが未訪問だったら
        if M[src][dst] == 1 and D[dst] == -1:
            dfs(dst)
    F[src] = time # 訪問終了時刻を記録
    time += 1
    # 関数の終わりで親に戻る(青矢印) dfs time = 1 1 time N = int(input()) int(input()) N b = [int(i+1 in a[2:]) for i in range(N)] [int(i+1 in a[2:]) for i in range(N)] b M = [] [] M F = [-1 for _ in range(N)] [-1 for _ in range(N)] F
N = int(input())
M = []
for i in range(N):
    a = list(map(int,input().strip().split()))
    b = [int(i+1 in a[2:]) for i in range(N)]
    M.append(b)

time = 1
D = [-1 for _ in range(N)]
F = [-1 for _ in range(N)]
def dfs(src):
    global time # 関数内でglobal変数の書き換えることを宣言
    D[src] = time # 訪問時刻を記録
    time += 1
    for dst in range(N):
        # srcからdstに移動可能で、dstが未訪問だったら
        if M[src][dst] == 1 and D[dst] == -1:
            dfs(dst)
    F[src] = time # 訪問終了時刻を記録
    time += 1
    # 関数の終わりで親に戻る(青矢印)

for root in range(N):
    # 番号が若い節点から
    if D[root] == -1:
        # D[root]が未訪問だったら
        dfs(root) # dfsを始める

[print(i+1, D[i], F[i]) for i in range(N)]

