n = int(input())
V = [[] for _ in range(n)]
for i in range(n):
    data = list(map(int, input().split(" ")))
    V[i] = data[2:]

answer = [[None, None] for _ in range(n)]

counter = 1


def dfs(v):
    global counter
    if answer[v][0] == None:
        answer[v][0] = counter
        counter += 1
        # ノードの子供の管理
        for e in V[v]:
            dfs(e-1)
        answer[v][1] = counter
        counter += 1


for i in range(len(answer)):
    if answer[i][0] == None:
        dfs(i)

for i in range(len(answer)):
    print(str(i+1) + " " + " ".join(map(str, answer[i])))
 n = int(input()) n int(input()) int input() input [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] V = [[] for _ in range(n)] V [[] for _ in range(n)] for i in range(n):
    data = list(map(int, input().split(" ")))
    V[i] = data[2:] i range(n) range n data = list(map(int, input().split(" "))) data list(map(int, input().split(" "))) list map(int, input().split(" ")) map int input().split(" ") ().split () input split " " V[i] = data[2:] V[i] V i data[2:] data 2: 2 [None, None] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [None, None] None None answer = [[None, None] for _ in range(n)] answer [[None, None] for _ in range(n)] counter = 1 counter 1 def dfs(v):
    global counter
    if answer[v][0] == None:
        answer[v][0] = counter
        counter += 1
        # ノードの子供の管理
        for e in V[v]:
            dfs(e-1)
        answer[v][1] = counter
        counter += 1 dfs global counter if answer[v][0] == None:
        answer[v][0] = counter
        counter += 1
        # ノードの子供の管理
        for e in V[v]:
            dfs(e-1)
        answer[v][1] = counter
        counter += 1 answer[v][0] == None answer[v][0] [v] answer v 0 None answer[v][0] = counter answer[v][0] [v] answer v 0 counter counter += 1 counter 1 for e in V[v]:
            dfs(e-1)
         e V[v] V v dfs(e-1) dfs e-1 e 1 answer[v][1] = counter answer[v][1] [v] answer v 1 counter counter += 1 counter 1 v v for i in range(len(answer)):
    if answer[i][0] == None:
        dfs(i) i range(len(answer)) range len(answer) len answer if answer[i][0] == None:
        dfs(i) answer[i][0] == None answer[i][0] [i] answer i 0 None dfs(i) dfs i for i in range(len(answer)):
    print(str(i+1) + " " + " ".join(map(str, answer[i]))) i range(len(answer)) range len(answer) len answer print(str(i+1) + " " + " ".join(map(str, answer[i]))) print str(i+1) + " " + " ".join(map(str, answer[i])) str(i+1) + " " str(i+1) str i+1 i 1 " " " ".join(map(str, answer[i])) " ".join " " join map(str, answer[i]) map str answer[i] answer i answer = [[None, None] for _ in range(n)] [[None, None] for _ in range(n)] answer n = int(input()) int(input()) n def dfs(v):
    global counter
    if answer[v][0] == None:
        answer[v][0] = counter
        counter += 1
        # ノードの子供の管理
        for e in V[v]:
            dfs(e-1)
        answer[v][1] = counter
        counter += 1 def dfs(v):
    global counter
    if answer[v][0] == None:
        answer[v][0] = counter
        counter += 1
        # ノードの子供の管理
        for e in V[v]:
            dfs(e-1)
        answer[v][1] = counter
        counter += 1 dfs V = [[] for _ in range(n)] [[] for _ in range(n)] V counter = 1 1 counter data = list(map(int, input().split(" "))) list(map(int, input().split(" "))) data
n = int(input())
V = [[] for _ in range(n)]
for i in range(n):
    data = list(map(int, input().split(" ")))
    V[i] = data[2:]

answer = [[None, None] for _ in range(n)]

counter = 1


def dfs(v):
    global counter
    if answer[v][0] == None:
        answer[v][0] = counter
        counter += 1
        # ノードの子供の管理
        for e in V[v]:
            dfs(e-1)
        answer[v][1] = counter
        counter += 1


for i in range(len(answer)):
    if answer[i][0] == None:
        dfs(i)

for i in range(len(answer)):
    print(str(i+1) + " " + " ".join(map(str, answer[i])))

