# -*- coding: utf-8 -*-
'''
所要時間は、分位であった。
'''


# ライブラリのインポート
#import re
import sys
input = sys.stdin.readline
#import heapq
#import bisect
import collections
#import math
global time, Ls, Lf, E,LG,c,n
time = 1

def main():
    global time, Ls, Lf, E, LG,c,n
    c = 0
    n = int(input().strip())
    E = [[] for _ in range(n)]
    LG = collections.deque()
    for line in sys.stdin:
        Ltmp = list(map(int, list(line.strip().split())))
        if not Ltmp[1] == 0: 
            E[Ltmp[0]-1] = Ltmp[2:]
    Ls = [0]*n 
    Lf = [0]*n
    dfs(0)
    for i in range(n):
        print(i+1, Ls[i],Lf[i])
    
def dfs(cur):
    global time, Ls, Lf, E, LG,c,n
    LG.append(cur)
    if Ls[cur] == 0: Ls[cur] = time
    time += 1
    for i in range(len(E[cur])):
        check = E[cur][i] - 1
        if Ls[check] == 0: dfs(check)
    if Lf[cur] == 0:
        Lf[cur] = time
    try:
        x = LG.pop()
        if x == cur: x = LG.pop() 
        dfs(x)
    except:
        time += 1
        for i in range(c,n):
            if Ls[i] == 0:
                c = i
                dfs(i) 
    return




    


    
if __name__ == '__main__':
    main()
 '''
所要時間は、分位であった。
''' import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline import collections collections global time, Ls, Lf, E,LG,c,n time = 1 time 1 def main():
    global time, Ls, Lf, E, LG,c,n
    c = 0
    n = int(input().strip())
    E = [[] for _ in range(n)]
    LG = collections.deque()
    for line in sys.stdin:
        Ltmp = list(map(int, list(line.strip().split())))
        if not Ltmp[1] == 0: 
            E[Ltmp[0]-1] = Ltmp[2:]
    Ls = [0]*n 
    Lf = [0]*n
    dfs(0)
    for i in range(n):
        print(i+1, Ls[i],Lf[i])
     main global time, Ls, Lf, E, LG,c,n c = 0 c 0 n = int(input().strip()) n int(input().strip()) int input().strip() ().strip () input strip [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] E = [[] for _ in range(n)] E [[] for _ in range(n)] LG = collections.deque() LG collections.deque() collections.deque collections deque for line in sys.stdin:
        Ltmp = list(map(int, list(line.strip().split())))
        if not Ltmp[1] == 0: 
            E[Ltmp[0]-1] = Ltmp[2:]
     line sys.stdin sys stdin Ltmp = list(map(int, list(line.strip().split()))) Ltmp list(map(int, list(line.strip().split()))) list map(int, list(line.strip().split())) map int list(line.strip().split()) list line.strip().split() line.strip().split line.strip() line.strip line strip split if not Ltmp[1] == 0: 
            E[Ltmp[0]-1] = Ltmp[2:]
     not Ltmp[1] == 0 Ltmp[1] == 0 Ltmp[1] Ltmp 1 0 E[Ltmp[0]-1] = Ltmp[2:] E[Ltmp[0]-1] E Ltmp[0]-1 Ltmp[0] Ltmp 0 1 Ltmp[2:] Ltmp 2: 2 Ls = [0]*n Ls [0]*n [0] 0 n Lf = [0]*n Lf [0]*n [0] 0 n dfs(0) dfs 0 for i in range(n):
        print(i+1, Ls[i],Lf[i])
     i range(n) range n print(i+1, Ls[i],Lf[i]) print i+1 i 1 Ls[i] Ls i Lf[i] Lf i def dfs(cur):
    global time, Ls, Lf, E, LG,c,n
    LG.append(cur)
    if Ls[cur] == 0: Ls[cur] = time
    time += 1
    for i in range(len(E[cur])):
        check = E[cur][i] - 1
        if Ls[check] == 0: dfs(check)
    if Lf[cur] == 0:
        Lf[cur] = time
    try:
        x = LG.pop()
        if x == cur: x = LG.pop() 
        dfs(x)
    except:
        time += 1
        for i in range(c,n):
            if Ls[i] == 0:
                c = i
                dfs(i) 
    return




    


     dfs global time, Ls, Lf, E, LG,c,n LG.append(cur) LG.append LG append cur if Ls[cur] == 0: Ls[cur] = time
     Ls[cur] == 0 Ls[cur] Ls cur 0 time += 1 time 1 for i in range(len(E[cur])):
        check = E[cur][i] - 1
        if Ls[check] == 0: dfs(check)
     i range(len(E[cur])) range len(E[cur]) len E[cur] E cur check = E[cur][i] - 1 check E[cur][i] - 1 E[cur][i] [cur] E cur i 1 if Ls[check] == 0: dfs(check)
     Ls[check] == 0 Ls[check] Ls check 0 if Lf[cur] == 0:
        Lf[cur] = time
     Lf[cur] == 0 Lf[cur] Lf cur 0 Lf[cur] = time Lf[cur] Lf cur time try:
        x = LG.pop()
        if x == cur: x = LG.pop() 
        dfs(x)
    except:
        time += 1
        for i in range(c,n):
            if Ls[i] == 0:
                c = i
                dfs(i) 
     except:
        time += 1
        for i in range(c,n):
            if Ls[i] == 0:
                c = i
                dfs(i) 
     time += 1 time 1 for i in range(c,n):
            if Ls[i] == 0:
                c = i
                dfs(i) 
     i range(c,n) range c n if Ls[i] == 0:
                c = i
                dfs(i) 
     Ls[i] == 0 Ls[i] Ls i 0 c = i c i dfs(i) dfs i x = LG.pop() x LG.pop() LG.pop LG pop if x == cur: x = LG.pop() 
         x == cur x cur dfs(x) dfs x return cur cur if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main global time, Ls, Lf, E,LG,c,n input = sys.stdin.readline sys.stdin.readline input def main():
    global time, Ls, Lf, E, LG,c,n
    c = 0
    n = int(input().strip())
    E = [[] for _ in range(n)]
    LG = collections.deque()
    for line in sys.stdin:
        Ltmp = list(map(int, list(line.strip().split())))
        if not Ltmp[1] == 0: 
            E[Ltmp[0]-1] = Ltmp[2:]
    Ls = [0]*n 
    Lf = [0]*n
    dfs(0)
    for i in range(n):
        print(i+1, Ls[i],Lf[i])
     def main():
    global time, Ls, Lf, E, LG,c,n
    c = 0
    n = int(input().strip())
    E = [[] for _ in range(n)]
    LG = collections.deque()
    for line in sys.stdin:
        Ltmp = list(map(int, list(line.strip().split())))
        if not Ltmp[1] == 0: 
            E[Ltmp[0]-1] = Ltmp[2:]
    Ls = [0]*n 
    Lf = [0]*n
    dfs(0)
    for i in range(n):
        print(i+1, Ls[i],Lf[i])
     main def dfs(cur):
    global time, Ls, Lf, E, LG,c,n
    LG.append(cur)
    if Ls[cur] == 0: Ls[cur] = time
    time += 1
    for i in range(len(E[cur])):
        check = E[cur][i] - 1
        if Ls[check] == 0: dfs(check)
    if Lf[cur] == 0:
        Lf[cur] = time
    try:
        x = LG.pop()
        if x == cur: x = LG.pop() 
        dfs(x)
    except:
        time += 1
        for i in range(c,n):
            if Ls[i] == 0:
                c = i
                dfs(i) 
    return




    


     def dfs(cur):
    global time, Ls, Lf, E, LG,c,n
    LG.append(cur)
    if Ls[cur] == 0: Ls[cur] = time
    time += 1
    for i in range(len(E[cur])):
        check = E[cur][i] - 1
        if Ls[check] == 0: dfs(check)
    if Lf[cur] == 0:
        Lf[cur] = time
    try:
        x = LG.pop()
        if x == cur: x = LG.pop() 
        dfs(x)
    except:
        time += 1
        for i in range(c,n):
            if Ls[i] == 0:
                c = i
                dfs(i) 
    return




    


     dfs time = 1 1 time
# -*- coding: utf-8 -*-
'''
所要時間は、分位であった。
'''


# ライブラリのインポート
#import re
import sys
input = sys.stdin.readline
#import heapq
#import bisect
import collections
#import math
global time, Ls, Lf, E,LG,c,n
time = 1

def main():
    global time, Ls, Lf, E, LG,c,n
    c = 0
    n = int(input().strip())
    E = [[] for _ in range(n)]
    LG = collections.deque()
    for line in sys.stdin:
        Ltmp = list(map(int, list(line.strip().split())))
        if not Ltmp[1] == 0: 
            E[Ltmp[0]-1] = Ltmp[2:]
    Ls = [0]*n 
    Lf = [0]*n
    dfs(0)
    for i in range(n):
        print(i+1, Ls[i],Lf[i])
    
def dfs(cur):
    global time, Ls, Lf, E, LG,c,n
    LG.append(cur)
    if Ls[cur] == 0: Ls[cur] = time
    time += 1
    for i in range(len(E[cur])):
        check = E[cur][i] - 1
        if Ls[check] == 0: dfs(check)
    if Lf[cur] == 0:
        Lf[cur] = time
    try:
        x = LG.pop()
        if x == cur: x = LG.pop() 
        dfs(x)
    except:
        time += 1
        for i in range(c,n):
            if Ls[i] == 0:
                c = i
                dfs(i) 
    return




    


    
if __name__ == '__main__':
    main()

