n = int(input())
graph = {}
ans = []
np = set(range(1,n+1))
for i in range(n):
    t = list(map(int, input().split()))
    v = t[0]
    k = t[1]
    graph[v] = [t[i+2] for i in range(k)]
    np=np - set(graph[v])
    ans.append([v,None,None])

class Time:
    def __init__(self):
        self.time = 0
    def getTime(self):
        self.time += 1
        return self.time

t = Time()

visited = set()
def dfs(graph, target):
    visited.add(target)
    # ???????????????????¨????
    if ans[target - 1][1] is None:
        ans[target - 1][1] = t.getTime()
    if graph[target] == []:
        if ans[target - 1][2] is None:
            ans[target - 1][2] = t.getTime()        
        return
    for v in sorted(graph[target]):
        # # ???????????????????¨????
        if v not in visited:        
            if ans[v - 1][1] is None:
                ans[v - 1][1] = t.getTime()        
            visited.add(target)
            dfs(graph,v)
    if ans[target - 1][2] is None:
        ans[target - 1][2] = t.getTime()

if np == set():
    np = [1]
for v in sorted(list(np)):
    dfs(graph,v)
for row in ans:
    print(*row) n = int(input()) n int(input()) int input() input graph = {} graph {} ans = [] ans [] np = set(range(1,n+1)) np set(range(1,n+1)) set range(1,n+1) range 1 n+1 n 1 for i in range(n):
    t = list(map(int, input().split()))
    v = t[0]
    k = t[1]
    graph[v] = [t[i+2] for i in range(k)]
    np=np - set(graph[v])
    ans.append([v,None,None]) i range(n) range n t = list(map(int, input().split())) t list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split v = t[0] v t[0] t 0 k = t[1] k t[1] t 1 t[i+2] for i in range(k) for i in range(k) i range(k) range k for i in range(k) t[i+2] t i+2 i 2 graph[v] = [t[i+2] for i in range(k)] graph[v] graph v [t[i+2] for i in range(k)] np=np - set(graph[v]) np np - set(graph[v]) np set(graph[v]) set graph[v] graph v ans.append([v,None,None]) ans.append ans append [v,None,None] v None None class Time:
    def __init__(self):
        self.time = 0
    def getTime(self):
        self.time += 1
        return self.time Time def __init__(self):
        self.time = 0
     __init__ self.time = 0 self.time self time 0 self self def getTime(self):
        self.time += 1
        return self.time getTime self.time += 1 self.time self time 1 return self.time self.time self time self self t = Time() t Time() Time visited = set() visited set() set def dfs(graph, target):
    visited.add(target)
    # ???????????????????¨????
    if ans[target - 1][1] is None:
        ans[target - 1][1] = t.getTime()
    if graph[target] == []:
        if ans[target - 1][2] is None:
            ans[target - 1][2] = t.getTime()        
        return
    for v in sorted(graph[target]):
        # # ???????????????????¨????
        if v not in visited:        
            if ans[v - 1][1] is None:
                ans[v - 1][1] = t.getTime()        
            visited.add(target)
            dfs(graph,v)
    if ans[target - 1][2] is None:
        ans[target - 1][2] = t.getTime() dfs visited.add(target) visited.add visited add target if ans[target - 1][1] is None:
        ans[target - 1][1] = t.getTime()
     ans[target - 1][1] is None ans[target - 1][1] [target - 1] ans target - 1 target 1 1 None ans[target - 1][1] = t.getTime() ans[target - 1][1] [target - 1] ans target - 1 target 1 1 t.getTime() t.getTime t getTime if graph[target] == []:
        if ans[target - 1][2] is None:
            ans[target - 1][2] = t.getTime()        
        return
     graph[target] == [] graph[target] graph target [] if ans[target - 1][2] is None:
            ans[target - 1][2] = t.getTime()        
         ans[target - 1][2] is None ans[target - 1][2] [target - 1] ans target - 1 target 1 2 None ans[target - 1][2] = t.getTime() ans[target - 1][2] [target - 1] ans target - 1 target 1 2 t.getTime() t.getTime t getTime return for v in sorted(graph[target]):
        # # ???????????????????¨????
        if v not in visited:        
            if ans[v - 1][1] is None:
                ans[v - 1][1] = t.getTime()        
            visited.add(target)
            dfs(graph,v)
     v sorted(graph[target]) sorted graph[target] graph target if v not in visited:        
            if ans[v - 1][1] is None:
                ans[v - 1][1] = t.getTime()        
            visited.add(target)
            dfs(graph,v)
     v not in visited v visited if ans[v - 1][1] is None:
                ans[v - 1][1] = t.getTime()        
             ans[v - 1][1] is None ans[v - 1][1] [v - 1] ans v - 1 v 1 1 None ans[v - 1][1] = t.getTime() ans[v - 1][1] [v - 1] ans v - 1 v 1 1 t.getTime() t.getTime t getTime visited.add(target) visited.add visited add target dfs(graph,v) dfs graph v if ans[target - 1][2] is None:
        ans[target - 1][2] = t.getTime() ans[target - 1][2] is None ans[target - 1][2] [target - 1] ans target - 1 target 1 2 None ans[target - 1][2] = t.getTime() ans[target - 1][2] [target - 1] ans target - 1 target 1 2 t.getTime() t.getTime t getTime graph graph target target if np == set():
    np = [1] np == set() np set() set np = [1] np [1] 1 for v in sorted(list(np)):
    dfs(graph,v) v sorted(list(np)) sorted list(np) list np dfs(graph,v) dfs graph v for row in ans:
    print(*row) row ans print(*row) print *row row def dfs(graph, target):
    visited.add(target)
    # ???????????????????¨????
    if ans[target - 1][1] is None:
        ans[target - 1][1] = t.getTime()
    if graph[target] == []:
        if ans[target - 1][2] is None:
            ans[target - 1][2] = t.getTime()        
        return
    for v in sorted(graph[target]):
        # # ???????????????????¨????
        if v not in visited:        
            if ans[v - 1][1] is None:
                ans[v - 1][1] = t.getTime()        
            visited.add(target)
            dfs(graph,v)
    if ans[target - 1][2] is None:
        ans[target - 1][2] = t.getTime() def dfs(graph, target):
    visited.add(target)
    # ???????????????????¨????
    if ans[target - 1][1] is None:
        ans[target - 1][1] = t.getTime()
    if graph[target] == []:
        if ans[target - 1][2] is None:
            ans[target - 1][2] = t.getTime()        
        return
    for v in sorted(graph[target]):
        # # ???????????????????¨????
        if v not in visited:        
            if ans[v - 1][1] is None:
                ans[v - 1][1] = t.getTime()        
            visited.add(target)
            dfs(graph,v)
    if ans[target - 1][2] is None:
        ans[target - 1][2] = t.getTime() dfs np = [1] [1] np class Time:
    def __init__(self):
        self.time = 0
    def getTime(self):
        self.time += 1
        return self.time class Time:
    def __init__(self):
        self.time = 0
    def getTime(self):
        self.time += 1
        return self.time Time graph = {} {} graph v = t[0] t[0] v visited = set() set() visited np=np - set(graph[v]) np - set(graph[v]) np n = int(input()) int(input()) n ans = [] [] ans np = set(range(1,n+1)) set(range(1,n+1)) np k = t[1] t[1] k t = list(map(int, input().split())) list(map(int, input().split())) t t = Time() Time() t
n = int(input())
graph = {}
ans = []
np = set(range(1,n+1))
for i in range(n):
    t = list(map(int, input().split()))
    v = t[0]
    k = t[1]
    graph[v] = [t[i+2] for i in range(k)]
    np=np - set(graph[v])
    ans.append([v,None,None])

class Time:
    def __init__(self):
        self.time = 0
    def getTime(self):
        self.time += 1
        return self.time

t = Time()

visited = set()
def dfs(graph, target):
    visited.add(target)
    # ???????????????????¨????
    if ans[target - 1][1] is None:
        ans[target - 1][1] = t.getTime()
    if graph[target] == []:
        if ans[target - 1][2] is None:
            ans[target - 1][2] = t.getTime()        
        return
    for v in sorted(graph[target]):
        # # ???????????????????¨????
        if v not in visited:        
            if ans[v - 1][1] is None:
                ans[v - 1][1] = t.getTime()        
            visited.add(target)
            dfs(graph,v)
    if ans[target - 1][2] is None:
        ans[target - 1][2] = t.getTime()

if np == set():
    np = [1]
for v in sorted(list(np)):
    dfs(graph,v)
for row in ans:
    print(*row)