import sys
from collections import defaultdict


time = 1


def dfs(g, visited, start, ans):
    global time
    visited[start - 1] = True
    ans[start - 1][0] = time
    for e in g[start]:
        if not visited[e - 1]:
            time += 1
            dfs(g, visited, e, ans)
    time += 1
    ans[start - 1][1] = time


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    g = defaultdict(list)
    for i in range(n):
        line = list(map(int, input().split()))
        if line[1] > 0:
            g[line[0]] = line[2:]
    visited = [False] * n

    ans = [[1, 1] for _ in range(n)]
    global time
    while False in visited:
        start = visited.index(False) + 1
        dfs(g, visited, start, ans)
        time += 1

    for i in range(1, n + 1):
        print(i, *ans[i - 1])


if __name__ == "__main__":
    main()
 import sys sys from collections import defaultdict time = 1 time 1 def dfs(g, visited, start, ans):
    global time
    visited[start - 1] = True
    ans[start - 1][0] = time
    for e in g[start]:
        if not visited[e - 1]:
            time += 1
            dfs(g, visited, e, ans)
    time += 1
    ans[start - 1][1] = time dfs global time visited[start - 1] = True visited[start - 1] visited start - 1 start 1 True ans[start - 1][0] = time ans[start - 1][0] [start - 1] ans start - 1 start 1 0 time for e in g[start]:
        if not visited[e - 1]:
            time += 1
            dfs(g, visited, e, ans)
     e g[start] g start if not visited[e - 1]:
            time += 1
            dfs(g, visited, e, ans)
     not visited[e - 1] visited[e - 1] visited e - 1 e 1 time += 1 time 1 dfs(g, visited, e, ans) dfs g visited e ans time += 1 time 1 ans[start - 1][1] = time ans[start - 1][1] [start - 1] ans start - 1 start 1 1 time g g visited visited start start ans ans def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    g = defaultdict(list)
    for i in range(n):
        line = list(map(int, input().split()))
        if line[1] > 0:
            g[line[0]] = line[2:]
    visited = [False] * n

    ans = [[1, 1] for _ in range(n)]
    global time
    while False in visited:
        start = visited.index(False) + 1
        dfs(g, visited, start, ans)
        time += 1

    for i in range(1, n + 1):
        print(i, *ans[i - 1]) main input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline n = int(input()) n int(input()) int input() input g = defaultdict(list) g defaultdict(list) defaultdict list for i in range(n):
        line = list(map(int, input().split()))
        if line[1] > 0:
            g[line[0]] = line[2:]
     i range(n) range n line = list(map(int, input().split())) line list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split if line[1] > 0:
            g[line[0]] = line[2:]
     line[1] > 0 line[1] line 1 0 g[line[0]] = line[2:] g[line[0]] g line[0] line 0 line[2:] line 2: 2 visited = [False] * n visited [False] * n [False] False n [1, 1] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [1, 1] 1 1 ans = [[1, 1] for _ in range(n)] ans [[1, 1] for _ in range(n)] global time while False in visited:
        start = visited.index(False) + 1
        dfs(g, visited, start, ans)
        time += 1

     False in visited False visited start = visited.index(False) + 1 start visited.index(False) + 1 visited.index(False) visited.index visited index False 1 dfs(g, visited, start, ans) dfs g visited start ans time += 1 time 1 for i in range(1, n + 1):
        print(i, *ans[i - 1]) i range(1, n + 1) range 1 n + 1 n 1 print(i, *ans[i - 1]) print i *ans[i - 1] ans[i - 1] ans i - 1 i 1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main time = 1 1 time def dfs(g, visited, start, ans):
    global time
    visited[start - 1] = True
    ans[start - 1][0] = time
    for e in g[start]:
        if not visited[e - 1]:
            time += 1
            dfs(g, visited, e, ans)
    time += 1
    ans[start - 1][1] = time def dfs(g, visited, start, ans):
    global time
    visited[start - 1] = True
    ans[start - 1][0] = time
    for e in g[start]:
        if not visited[e - 1]:
            time += 1
            dfs(g, visited, e, ans)
    time += 1
    ans[start - 1][1] = time dfs def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    g = defaultdict(list)
    for i in range(n):
        line = list(map(int, input().split()))
        if line[1] > 0:
            g[line[0]] = line[2:]
    visited = [False] * n

    ans = [[1, 1] for _ in range(n)]
    global time
    while False in visited:
        start = visited.index(False) + 1
        dfs(g, visited, start, ans)
        time += 1

    for i in range(1, n + 1):
        print(i, *ans[i - 1]) def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    g = defaultdict(list)
    for i in range(n):
        line = list(map(int, input().split()))
        if line[1] > 0:
            g[line[0]] = line[2:]
    visited = [False] * n

    ans = [[1, 1] for _ in range(n)]
    global time
    while False in visited:
        start = visited.index(False) + 1
        dfs(g, visited, start, ans)
        time += 1

    for i in range(1, n + 1):
        print(i, *ans[i - 1]) main
import sys
from collections import defaultdict


time = 1


def dfs(g, visited, start, ans):
    global time
    visited[start - 1] = True
    ans[start - 1][0] = time
    for e in g[start]:
        if not visited[e - 1]:
            time += 1
            dfs(g, visited, e, ans)
    time += 1
    ans[start - 1][1] = time


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    g = defaultdict(list)
    for i in range(n):
        line = list(map(int, input().split()))
        if line[1] > 0:
            g[line[0]] = line[2:]
    visited = [False] * n

    ans = [[1, 1] for _ in range(n)]
    global time
    while False in visited:
        start = visited.index(False) + 1
        dfs(g, visited, start, ans)
        time += 1

    for i in range(1, n + 1):
        print(i, *ans[i - 1])


if __name__ == "__main__":
    main()

