import sys
# sys.stdin = open('input.txt')

def fillMatrix():
    for i in range(n):
        u, k, *v = map(int, input().split())
        for j in v:
            matrix[i][j-1] = 1

def dfs(u):
    global time
    status[u] = VISITING
    time += 1
    discoverTime[u] = time
    for v in range(n):
        if matrix[u][v] and status[v] == NOT_VISITED:
            dfs(v)
    status[u] = VISITED
    time += 1
    finishTime[u] = time


n = int(input())
matrix = [[0]*n for i in range(n)]
time = 0
discoverTime = [0] * n
finishTime = [0] * n

NOT_VISITED = 0 # WHITE
VISITING = 1 # GRAY
VISITED = 2 # BLACK
status = [NOT_VISITED] * n

fillMatrix()
# Calling dfs(0) alone cannot reach nodes not connected from 0
for i in range(n):
    if status[i] != VISITED:
        dfs(i)

for i in range(n):
    ans = []
    ans.append(i+1)
    ans.append(discoverTime[i])
    ans.append(finishTime[i])
    ans = map(str, ans)
    print(' '.join(ans)) import sys sys def fillMatrix():
    for i in range(n):
        u, k, *v = map(int, input().split())
        for j in v:
            matrix[i][j-1] = 1 fillMatrix for i in range(n):
        u, k, *v = map(int, input().split())
        for j in v:
            matrix[i][j-1] = 1 i range(n) range n u, k, *v = map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split k *v v for j in v:
            matrix[i][j-1] = 1 j v matrix[i][j-1] = 1 matrix[i][j-1] [i] matrix i j-1 j 1 1 def dfs(u):
    global time
    status[u] = VISITING
    time += 1
    discoverTime[u] = time
    for v in range(n):
        if matrix[u][v] and status[v] == NOT_VISITED:
            dfs(v)
    status[u] = VISITED
    time += 1
    finishTime[u] = time dfs global time status[u] = VISITING status[u] status u VISITING time += 1 time 1 discoverTime[u] = time discoverTime[u] discoverTime u time for v in range(n):
        if matrix[u][v] and status[v] == NOT_VISITED:
            dfs(v)
     v range(n) range n if matrix[u][v] and status[v] == NOT_VISITED:
            dfs(v)
     matrix[u][v] and status[v] == NOT_VISITED matrix[u][v] [u] matrix u v status[v] == NOT_VISITED status[v] status v NOT_VISITED dfs(v) dfs v status[u] = VISITED status[u] status u VISITED time += 1 time 1 finishTime[u] = time finishTime[u] finishTime u time u u n = int(input()) n int(input()) int input() input [0]*n for i in range(n) for i in range(n) i range(n) range n for i in range(n) [0]*n [0] 0 n matrix = [[0]*n for i in range(n)] matrix [[0]*n for i in range(n)] time = 0 time 0 discoverTime = [0] * n discoverTime [0] * n [0] 0 n finishTime = [0] * n finishTime [0] * n [0] 0 n NOT_VISITED = 0 NOT_VISITED 0 VISITING = 1 VISITING 1 VISITED = 2 VISITED 2 status = [NOT_VISITED] * n status [NOT_VISITED] * n [NOT_VISITED] NOT_VISITED n fillMatrix() fillMatrix for i in range(n):
    if status[i] != VISITED:
        dfs(i) i range(n) range n if status[i] != VISITED:
        dfs(i) status[i] != VISITED status[i] status i VISITED dfs(i) dfs i for i in range(n):
    ans = []
    ans.append(i+1)
    ans.append(discoverTime[i])
    ans.append(finishTime[i])
    ans = map(str, ans)
    print(' '.join(ans)) i range(n) range n ans = [] ans [] ans.append(i+1) ans.append ans append i+1 i 1 ans.append(discoverTime[i]) ans.append ans append discoverTime[i] discoverTime i ans.append(finishTime[i]) ans.append ans append finishTime[i] finishTime i ans = map(str, ans) ans map(str, ans) map str ans print(' '.join(ans)) print ' '.join(ans) ' '.join ' ' join ans time = 0 0 time ans = [] [] ans matrix = [[0]*n for i in range(n)] [[0]*n for i in range(n)] matrix status = [NOT_VISITED] * n [NOT_VISITED] * n status n = int(input()) int(input()) n def fillMatrix():
    for i in range(n):
        u, k, *v = map(int, input().split())
        for j in v:
            matrix[i][j-1] = 1 def fillMatrix():
    for i in range(n):
        u, k, *v = map(int, input().split())
        for j in v:
            matrix[i][j-1] = 1 fillMatrix NOT_VISITED = 0 0 NOT_VISITED discoverTime = [0] * n [0] * n discoverTime finishTime = [0] * n [0] * n finishTime def dfs(u):
    global time
    status[u] = VISITING
    time += 1
    discoverTime[u] = time
    for v in range(n):
        if matrix[u][v] and status[v] == NOT_VISITED:
            dfs(v)
    status[u] = VISITED
    time += 1
    finishTime[u] = time def dfs(u):
    global time
    status[u] = VISITING
    time += 1
    discoverTime[u] = time
    for v in range(n):
        if matrix[u][v] and status[v] == NOT_VISITED:
            dfs(v)
    status[u] = VISITED
    time += 1
    finishTime[u] = time dfs VISITED = 2 2 VISITED VISITING = 1 1 VISITING ans = map(str, ans) map(str, ans) ans
import sys
# sys.stdin = open('input.txt')

def fillMatrix():
    for i in range(n):
        u, k, *v = map(int, input().split())
        for j in v:
            matrix[i][j-1] = 1

def dfs(u):
    global time
    status[u] = VISITING
    time += 1
    discoverTime[u] = time
    for v in range(n):
        if matrix[u][v] and status[v] == NOT_VISITED:
            dfs(v)
    status[u] = VISITED
    time += 1
    finishTime[u] = time


n = int(input())
matrix = [[0]*n for i in range(n)]
time = 0
discoverTime = [0] * n
finishTime = [0] * n

NOT_VISITED = 0 # WHITE
VISITING = 1 # GRAY
VISITED = 2 # BLACK
status = [NOT_VISITED] * n

fillMatrix()
# Calling dfs(0) alone cannot reach nodes not connected from 0
for i in range(n):
    if status[i] != VISITED:
        dfs(i)

for i in range(n):
    ans = []
    ans.append(i+1)
    ans.append(discoverTime[i])
    ans.append(finishTime[i])
    ans = map(str, ans)
    print(' '.join(ans))
