import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

global time
time = 0

def dfs(u: int, visited: list, d: list, f: list, M: list, n: int):
    global time
    visited[u] = True
    time += 1
    d[u] = time
    for j in range(n):
        if M[u][j] == 1 and not visited[j]:
            dfs(j, visited, d, f, M, n)
    time += 1
    f[u] += time

def main():
    n = int(input())
    visited = [False] * n
    M = [[0]*n for _ in range(n)]
    for _ in range(n):
        a = list(map(int, input().split()))
        for i in range(a[1]):
            M[a[0]-1][a[i+2]-1] = 1
    d = [0] * n
    f = [0] * n
    for i in range(n):
        if not visited[i]:
            dfs(i, visited, d, f, M, n)
    for i in range(n):
        print(i+1, d[i], f[i])

if __name__ == '__main__': main() import sys sys sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline global time time = 0 time 0 def dfs(u: int, visited: list, d: list, f: list, M: list, n: int):
    global time
    visited[u] = True
    time += 1
    d[u] = time
    for j in range(n):
        if M[u][j] == 1 and not visited[j]:
            dfs(j, visited, d, f, M, n)
    time += 1
    f[u] += time dfs global time visited[u] = True visited[u] visited u True time += 1 time 1 d[u] = time d[u] d u time for j in range(n):
        if M[u][j] == 1 and not visited[j]:
            dfs(j, visited, d, f, M, n)
     j range(n) range n if M[u][j] == 1 and not visited[j]:
            dfs(j, visited, d, f, M, n)
     M[u][j] == 1 and not visited[j] M[u][j] == 1 M[u][j] [u] M u j 1 not visited[j] visited[j] visited j dfs(j, visited, d, f, M, n) dfs j visited d f M n time += 1 time 1 f[u] += time f[u] f u time u: int u visited: list visited d: list d f: list f M: list M n: int n def main():
    n = int(input())
    visited = [False] * n
    M = [[0]*n for _ in range(n)]
    for _ in range(n):
        a = list(map(int, input().split()))
        for i in range(a[1]):
            M[a[0]-1][a[i+2]-1] = 1
    d = [0] * n
    f = [0] * n
    for i in range(n):
        if not visited[i]:
            dfs(i, visited, d, f, M, n)
    for i in range(n):
        print(i+1, d[i], f[i]) main n = int(input()) n int(input()) int input() input visited = [False] * n visited [False] * n [False] False n [0]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0]*n [0] 0 n M = [[0]*n for _ in range(n)] M [[0]*n for _ in range(n)] for _ in range(n):
        a = list(map(int, input().split()))
        for i in range(a[1]):
            M[a[0]-1][a[i+2]-1] = 1
     _ 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 in range(a[1]):
            M[a[0]-1][a[i+2]-1] = 1
     i range(a[1]) range a[1] a 1 M[a[0]-1][a[i+2]-1] = 1 M[a[0]-1][a[i+2]-1] [a[0]-1] M a[0]-1 a[0] a 0 1 a[i+2]-1 a[i+2] a i+2 i 2 1 1 d = [0] * n d [0] * n [0] 0 n f = [0] * n f [0] * n [0] 0 n for i in range(n):
        if not visited[i]:
            dfs(i, visited, d, f, M, n)
     i range(n) range n if not visited[i]:
            dfs(i, visited, d, f, M, n)
     not visited[i] visited[i] visited i dfs(i, visited, d, f, M, n) dfs i visited d f M n for i in range(n):
        print(i+1, d[i], f[i]) i range(n) range n print(i+1, d[i], f[i]) print i+1 i 1 d[i] d i f[i] f i if __name__ == '__main__': main() __name__ == '__main__' __name__ '__main__' def main():
    n = int(input())
    visited = [False] * n
    M = [[0]*n for _ in range(n)]
    for _ in range(n):
        a = list(map(int, input().split()))
        for i in range(a[1]):
            M[a[0]-1][a[i+2]-1] = 1
    d = [0] * n
    f = [0] * n
    for i in range(n):
        if not visited[i]:
            dfs(i, visited, d, f, M, n)
    for i in range(n):
        print(i+1, d[i], f[i]) def main():
    n = int(input())
    visited = [False] * n
    M = [[0]*n for _ in range(n)]
    for _ in range(n):
        a = list(map(int, input().split()))
        for i in range(a[1]):
            M[a[0]-1][a[i+2]-1] = 1
    d = [0] * n
    f = [0] * n
    for i in range(n):
        if not visited[i]:
            dfs(i, visited, d, f, M, n)
    for i in range(n):
        print(i+1, d[i], f[i]) main global time time = 0 0 time input = sys.stdin.readline sys.stdin.readline input def dfs(u: int, visited: list, d: list, f: list, M: list, n: int):
    global time
    visited[u] = True
    time += 1
    d[u] = time
    for j in range(n):
        if M[u][j] == 1 and not visited[j]:
            dfs(j, visited, d, f, M, n)
    time += 1
    f[u] += time def dfs(u: int, visited: list, d: list, f: list, M: list, n: int):
    global time
    visited[u] = True
    time += 1
    d[u] = time
    for j in range(n):
        if M[u][j] == 1 and not visited[j]:
            dfs(j, visited, d, f, M, n)
    time += 1
    f[u] += time dfs
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

global time
time = 0

def dfs(u: int, visited: list, d: list, f: list, M: list, n: int):
    global time
    visited[u] = True
    time += 1
    d[u] = time
    for j in range(n):
        if M[u][j] == 1 and not visited[j]:
            dfs(j, visited, d, f, M, n)
    time += 1
    f[u] += time

def main():
    n = int(input())
    visited = [False] * n
    M = [[0]*n for _ in range(n)]
    for _ in range(n):
        a = list(map(int, input().split()))
        for i in range(a[1]):
            M[a[0]-1][a[i+2]-1] = 1
    d = [0] * n
    f = [0] * n
    for i in range(n):
        if not visited[i]:
            dfs(i, visited, d, f, M, n)
    for i in range(n):
        print(i+1, d[i], f[i])

if __name__ == '__main__': main()
