n = int(input())
graph = {}

for i in range(1, n + 1):
    data = input().split()
    graph[i] = [int(i) for i in data[2:]]


class dfs:
    def __init__(self, graph):
        self.g = graph
        self.visited = set()
        self.time = 0
        self.res = {}

    def dfs(self, cur):
        self.visited.add(cur)
        self.time += 1
        start = self.time
        for node in self.g[cur]:
            if node not in self.visited:
                self.dfs(node)
        self.time += 1
        end = self.time
        self.res[cur] = (start, end)


solver = dfs(graph)
for i in range(1, n + 1):
    if i not in solver.visited:
        solver.dfs(i)

for i in range(1, n + 1):
    print(i, solver.res[i][0], solver.res[i][1])
 n = int(input()) n int(input()) int input() input graph = {} graph {} for i in range(1, n + 1):
    data = input().split()
    graph[i] = [int(i) for i in data[2:]] i range(1, n + 1) range 1 n + 1 n 1 data = input().split() data input().split() ().split () input split int(i) for i in data[2:] for i in data[2:] i data[2:] data 2: 2 for i in data[2:] int(i) int i graph[i] = [int(i) for i in data[2:]] graph[i] graph i [int(i) for i in data[2:]] class dfs:
    def __init__(self, graph):
        self.g = graph
        self.visited = set()
        self.time = 0
        self.res = {}

    def dfs(self, cur):
        self.visited.add(cur)
        self.time += 1
        start = self.time
        for node in self.g[cur]:
            if node not in self.visited:
                self.dfs(node)
        self.time += 1
        end = self.time
        self.res[cur] = (start, end) dfs def __init__(self, graph):
        self.g = graph
        self.visited = set()
        self.time = 0
        self.res = {}

     __init__ self.g = graph self.g self g graph self.visited = set() self.visited self visited set() set self.time = 0 self.time self time 0 self.res = {} self.res self res {} self self graph graph def dfs(self, cur):
        self.visited.add(cur)
        self.time += 1
        start = self.time
        for node in self.g[cur]:
            if node not in self.visited:
                self.dfs(node)
        self.time += 1
        end = self.time
        self.res[cur] = (start, end) dfs self.visited.add(cur) self.visited.add self.visited self visited add cur self.time += 1 self.time self time 1 start = self.time start self.time self time for node in self.g[cur]:
            if node not in self.visited:
                self.dfs(node)
         node self.g[cur] self.g self g cur if node not in self.visited:
                self.dfs(node)
         node not in self.visited node self.visited self visited self.dfs(node) self.dfs self dfs node self.time += 1 self.time self time 1 end = self.time end self.time self time self.res[cur] = (start, end) self.res[cur] self.res self res cur (start, end) start end self self cur cur solver = dfs(graph) solver dfs(graph) dfs graph for i in range(1, n + 1):
    if i not in solver.visited:
        solver.dfs(i) i range(1, n + 1) range 1 n + 1 n 1 if i not in solver.visited:
        solver.dfs(i) i not in solver.visited i solver.visited solver visited solver.dfs(i) solver.dfs solver dfs i for i in range(1, n + 1):
    print(i, solver.res[i][0], solver.res[i][1]) i range(1, n + 1) range 1 n + 1 n 1 print(i, solver.res[i][0], solver.res[i][1]) print i solver.res[i][0] solver.res[i] solver.res solver res i 0 solver.res[i][1] solver.res[i] solver.res solver res i 1 class dfs:
    def __init__(self, graph):
        self.g = graph
        self.visited = set()
        self.time = 0
        self.res = {}

    def dfs(self, cur):
        self.visited.add(cur)
        self.time += 1
        start = self.time
        for node in self.g[cur]:
            if node not in self.visited:
                self.dfs(node)
        self.time += 1
        end = self.time
        self.res[cur] = (start, end) class dfs:
    def __init__(self, graph):
        self.g = graph
        self.visited = set()
        self.time = 0
        self.res = {}

    def dfs(self, cur):
        self.visited.add(cur)
        self.time += 1
        start = self.time
        for node in self.g[cur]:
            if node not in self.visited:
                self.dfs(node)
        self.time += 1
        end = self.time
        self.res[cur] = (start, end) dfs data = input().split() input().split() data graph = {} {} graph n = int(input()) int(input()) n solver = dfs(graph) dfs(graph) solver
n = int(input())
graph = {}

for i in range(1, n + 1):
    data = input().split()
    graph[i] = [int(i) for i in data[2:]]


class dfs:
    def __init__(self, graph):
        self.g = graph
        self.visited = set()
        self.time = 0
        self.res = {}

    def dfs(self, cur):
        self.visited.add(cur)
        self.time += 1
        start = self.time
        for node in self.g[cur]:
            if node not in self.visited:
                self.dfs(node)
        self.time += 1
        end = self.time
        self.res[cur] = (start, end)


solver = dfs(graph)
for i in range(1, n + 1):
    if i not in solver.visited:
        solver.dfs(i)

for i in range(1, n + 1):
    print(i, solver.res[i][0], solver.res[i][1])

