N = int(input())
edge = [[0] for _ in range(N)]
for i in range(N):
    A = list(map(int, input().split()))
    for i,a in enumerate(A):
        A[i] -= 1
    edge[A[0]] = sorted(A[2:])
ans = [[0,0] for _ in range(N)]
import sys
sys.setrecursionlimit(10**8)

def dfs(v,now):
    if len(edge[v])>0:
        for u in edge[v]:
            if visited[u]==False:
                visited[u]=True
                now += 1
                ans[u][0] = now
                now = dfs(u,now)
    now += 1
    ans[v][1] = now
    return now

visited = [False]*N

now = 0
for i in range(N):
    if visited[i]==False:
        visited[i]=True
        now += 1
        ans[i][0] = now
        now = dfs(i,now)
for i in range(N):
    ans[i] = '{} {} {}'.format(i+1,ans[i][0],ans[i][1])
print(*ans,sep='\n') N = int(input()) N int(input()) int input() input [0] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [0] 0 edge = [[0] for _ in range(N)] edge [[0] for _ in range(N)] for i in range(N):
    A = list(map(int, input().split()))
    for i,a in enumerate(A):
        A[i] -= 1
    edge[A[0]] = sorted(A[2:]) 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 i,a in enumerate(A):
        A[i] -= 1
     i a enumerate(A) enumerate A A[i] -= 1 A[i] A i 1 edge[A[0]] = sorted(A[2:]) edge[A[0]] edge A[0] A 0 sorted(A[2:]) sorted A[2:] A 2: 2 [0,0] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [0,0] 0 0 ans = [[0,0] for _ in range(N)] ans [[0,0] for _ in range(N)] import sys sys sys.setrecursionlimit(10**8) sys.setrecursionlimit sys setrecursionlimit 10**8 10 8 def dfs(v,now):
    if len(edge[v])>0:
        for u in edge[v]:
            if visited[u]==False:
                visited[u]=True
                now += 1
                ans[u][0] = now
                now = dfs(u,now)
    now += 1
    ans[v][1] = now
    return now dfs if len(edge[v])>0:
        for u in edge[v]:
            if visited[u]==False:
                visited[u]=True
                now += 1
                ans[u][0] = now
                now = dfs(u,now)
     len(edge[v])>0 len(edge[v]) len edge[v] edge v 0 for u in edge[v]:
            if visited[u]==False:
                visited[u]=True
                now += 1
                ans[u][0] = now
                now = dfs(u,now)
     u edge[v] edge v if visited[u]==False:
                visited[u]=True
                now += 1
                ans[u][0] = now
                now = dfs(u,now)
     visited[u]==False visited[u] visited u False visited[u]=True visited[u] visited u True now += 1 now 1 ans[u][0] = now ans[u][0] [u] ans u 0 now now = dfs(u,now) now dfs(u,now) dfs u now now += 1 now 1 ans[v][1] = now ans[v][1] [v] ans v 1 now return now now v v now now visited = [False]*N visited [False]*N [False] False N now = 0 now 0 for i in range(N):
    if visited[i]==False:
        visited[i]=True
        now += 1
        ans[i][0] = now
        now = dfs(i,now) i range(N) range N if visited[i]==False:
        visited[i]=True
        now += 1
        ans[i][0] = now
        now = dfs(i,now) visited[i]==False visited[i] visited i False visited[i]=True visited[i] visited i True now += 1 now 1 ans[i][0] = now ans[i][0] [i] ans i 0 now now = dfs(i,now) now dfs(i,now) dfs i now for i in range(N):
    ans[i] = '{} {} {}'.format(i+1,ans[i][0],ans[i][1]) i range(N) range N ans[i] = '{} {} {}'.format(i+1,ans[i][0],ans[i][1]) ans[i] ans i '{} {} {}'.format(i+1,ans[i][0],ans[i][1]) '{} {} {}'.format '{} {} {}' format i+1 i 1 ans[i][0] [i] ans i 0 ans[i][1] [i] ans i 1 print(*ans,sep='\n') print *ans ans sep='\n' sep '\n' A = list(map(int, input().split())) list(map(int, input().split())) A def dfs(v,now):
    if len(edge[v])>0:
        for u in edge[v]:
            if visited[u]==False:
                visited[u]=True
                now += 1
                ans[u][0] = now
                now = dfs(u,now)
    now += 1
    ans[v][1] = now
    return now def dfs(v,now):
    if len(edge[v])>0:
        for u in edge[v]:
            if visited[u]==False:
                visited[u]=True
                now += 1
                ans[u][0] = now
                now = dfs(u,now)
    now += 1
    ans[v][1] = now
    return now dfs edge = [[0] for _ in range(N)] [[0] for _ in range(N)] edge N = int(input()) int(input()) N now = dfs(i,now) dfs(i,now) now now = 0 0 now now += 1 1 now ans = [[0,0] for _ in range(N)] [[0,0] for _ in range(N)] ans visited = [False]*N [False]*N visited
N = int(input())
edge = [[0] for _ in range(N)]
for i in range(N):
    A = list(map(int, input().split()))
    for i,a in enumerate(A):
        A[i] -= 1
    edge[A[0]] = sorted(A[2:])
ans = [[0,0] for _ in range(N)]
import sys
sys.setrecursionlimit(10**8)

def dfs(v,now):
    if len(edge[v])>0:
        for u in edge[v]:
            if visited[u]==False:
                visited[u]=True
                now += 1
                ans[u][0] = now
                now = dfs(u,now)
    now += 1
    ans[v][1] = now
    return now

visited = [False]*N

now = 0
for i in range(N):
    if visited[i]==False:
        visited[i]=True
        now += 1
        ans[i][0] = now
        now = dfs(i,now)
for i in range(N):
    ans[i] = '{} {} {}'.format(i+1,ans[i][0],ans[i][1])
print(*ans,sep='\n')
