import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

G = [[] for _ in range(105)]
begin = [-1] * 105
end = [-1] * 105

t = 1
def dfs(v):
    global t
    begin[v] = t
    t += 1
    for e in G[v]:
        if begin[e] < 0:
            dfs(e)
    end[v] = t
    t += 1

def main():
    N = int(input())
    for i in range(N):
        A = list(map(int,input().split()))
        for a in A[2:]:
            G[i].append(a - 1)
    
    for i in range(N):
        if begin[i] < 0:
            dfs(i)
    for i in range(N):
        print(i + 1,begin[i],end[i])
if __name__ == '__main__':
    main() import sys sys sys.setrecursionlimit(10000000) sys.setrecursionlimit sys setrecursionlimit 10000000 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 INF = 10 ** 15 INF 10 ** 15 10 15 [] for _ in range(105) for _ in range(105) _ range(105) range 105 for _ in range(105) [] G = [[] for _ in range(105)] G [[] for _ in range(105)] begin = [-1] * 105 begin [-1] * 105 [-1] -1 105 end = [-1] * 105 end [-1] * 105 [-1] -1 105 t = 1 t 1 def dfs(v):
    global t
    begin[v] = t
    t += 1
    for e in G[v]:
        if begin[e] < 0:
            dfs(e)
    end[v] = t
    t += 1 dfs global t begin[v] = t begin[v] begin v t t += 1 t 1 for e in G[v]:
        if begin[e] < 0:
            dfs(e)
     e G[v] G v if begin[e] < 0:
            dfs(e)
     begin[e] < 0 begin[e] begin e 0 dfs(e) dfs e end[v] = t end[v] end v t t += 1 t 1 v v def main():
    N = int(input())
    for i in range(N):
        A = list(map(int,input().split()))
        for a in A[2:]:
            G[i].append(a - 1)
    
    for i in range(N):
        if begin[i] < 0:
            dfs(i)
    for i in range(N):
        print(i + 1,begin[i],end[i]) main N = int(input()) N int(input()) int input() input for i in range(N):
        A = list(map(int,input().split()))
        for a in A[2:]:
            G[i].append(a - 1)
    
     i range(N) range N A = list(map(int,input().split())) A list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split for a in A[2:]:
            G[i].append(a - 1)
    
     a A[2:] A 2: 2 G[i].append(a - 1) [i].append [i] G i append a - 1 a 1 for i in range(N):
        if begin[i] < 0:
            dfs(i)
     i range(N) range N if begin[i] < 0:
            dfs(i)
     begin[i] < 0 begin[i] begin i 0 dfs(i) dfs i for i in range(N):
        print(i + 1,begin[i],end[i]) i range(N) range N print(i + 1,begin[i],end[i]) print i + 1 i 1 begin[i] begin i end[i] end i if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def dfs(v):
    global t
    begin[v] = t
    t += 1
    for e in G[v]:
        if begin[e] < 0:
            dfs(e)
    end[v] = t
    t += 1 def dfs(v):
    global t
    begin[v] = t
    t += 1
    for e in G[v]:
        if begin[e] < 0:
            dfs(e)
    end[v] = t
    t += 1 dfs INF = 10 ** 15 10 ** 15 INF G = [[] for _ in range(105)] [[] for _ in range(105)] G MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD t = 1 1 t end = [-1] * 105 [-1] * 105 end def main():
    N = int(input())
    for i in range(N):
        A = list(map(int,input().split()))
        for a in A[2:]:
            G[i].append(a - 1)
    
    for i in range(N):
        if begin[i] < 0:
            dfs(i)
    for i in range(N):
        print(i + 1,begin[i],end[i]) def main():
    N = int(input())
    for i in range(N):
        A = list(map(int,input().split()))
        for a in A[2:]:
            G[i].append(a - 1)
    
    for i in range(N):
        if begin[i] < 0:
            dfs(i)
    for i in range(N):
        print(i + 1,begin[i],end[i]) main begin = [-1] * 105 [-1] * 105 begin
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

G = [[] for _ in range(105)]
begin = [-1] * 105
end = [-1] * 105

t = 1
def dfs(v):
    global t
    begin[v] = t
    t += 1
    for e in G[v]:
        if begin[e] < 0:
            dfs(e)
    end[v] = t
    t += 1

def main():
    N = int(input())
    for i in range(N):
        A = list(map(int,input().split()))
        for a in A[2:]:
            G[i].append(a - 1)
    
    for i in range(N):
        if begin[i] < 0:
            dfs(i)
    for i in range(N):
        print(i + 1,begin[i],end[i])
if __name__ == '__main__':
    main()
