N = int(input())
UK = [list(map(int,input().split())) for _ in range(N)]

class Graph:
    def __init__(self,vertex,edge):
        self.v = vertex
        self.e = edge
        self.v_color = [False for _ in range(N)]

    def color(self,u):
        self.v_color[u-1] = True

    def v_exists(self,u):
        flag = False
        for v in self.v:
            if (u,v) in self.e and self.v_color[v-1] == False:
                flag = True
                break
        return flag

V = [i+1 for i in range(N)]
E = []
for i in range(N):
    for j in range(len(UK[i])-2):
        E.append((i+1,UK[i][j+2]))

g = Graph(V,E)

ts = [[0 for _ in range(2)] for _ in range(N+1)]
time = 0

def dfs(u):
    global time
    time += 1
    g.color(u)
    if ts[u-1][0] == 0:
        ts[u-1][0] = time
    while g.v_exists(u):
        for v in g.v:
            if (u,v) in g.e and g.v_color[v-1] == False:
                dfs(v)
    time += 1
    if ts[u-1][1] == 0:
        ts[u-1][1] = time

for i in range(N):
    if g.v_color[i] == False:
        dfs(i+1)

for i in range(N):
    print(i+1,ts[i][0],ts[i][1])
 N = int(input()) N int(input()) int input() input list(map(int,input().split())) for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split UK = [list(map(int,input().split())) for _ in range(N)] UK [list(map(int,input().split())) for _ in range(N)] class Graph:
    def __init__(self,vertex,edge):
        self.v = vertex
        self.e = edge
        self.v_color = [False for _ in range(N)]

    def color(self,u):
        self.v_color[u-1] = True

    def v_exists(self,u):
        flag = False
        for v in self.v:
            if (u,v) in self.e and self.v_color[v-1] == False:
                flag = True
                break
        return flag Graph def __init__(self,vertex,edge):
        self.v = vertex
        self.e = edge
        self.v_color = [False for _ in range(N)]

     __init__ self.v = vertex self.v self v vertex self.e = edge self.e self e edge False for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) False self.v_color = [False for _ in range(N)] self.v_color self v_color [False for _ in range(N)] self self vertex vertex edge edge def color(self,u):
        self.v_color[u-1] = True

     color self.v_color[u-1] = True self.v_color[u-1] self.v_color self v_color u-1 u 1 True self self u u def v_exists(self,u):
        flag = False
        for v in self.v:
            if (u,v) in self.e and self.v_color[v-1] == False:
                flag = True
                break
        return flag v_exists flag = False flag False for v in self.v:
            if (u,v) in self.e and self.v_color[v-1] == False:
                flag = True
                break
         v self.v self v if (u,v) in self.e and self.v_color[v-1] == False:
                flag = True
                break
         (u,v) in self.e and self.v_color[v-1] == False (u,v) in self.e (u,v) u v self.e self e self.v_color[v-1] == False self.v_color[v-1] self.v_color self v_color v-1 v 1 False flag = True flag True break return flag flag self self u u i+1 for i in range(N) for i in range(N) i range(N) range N for i in range(N) i+1 i 1 V = [i+1 for i in range(N)] V [i+1 for i in range(N)] E = [] E [] for i in range(N):
    for j in range(len(UK[i])-2):
        E.append((i+1,UK[i][j+2])) i range(N) range N for j in range(len(UK[i])-2):
        E.append((i+1,UK[i][j+2])) j range(len(UK[i])-2) range len(UK[i])-2 len(UK[i]) len UK[i] UK i 2 E.append((i+1,UK[i][j+2])) E.append E append (i+1,UK[i][j+2]) i+1 i 1 UK[i][j+2] [i] UK i j+2 j 2 g = Graph(V,E) g Graph(V,E) Graph V E [0 for _ in range(2)] for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [0 for _ in range(2)] ts = [[0 for _ in range(2)] for _ in range(N+1)] ts [[0 for _ in range(2)] for _ in range(N+1)] time = 0 time 0 def dfs(u):
    global time
    time += 1
    g.color(u)
    if ts[u-1][0] == 0:
        ts[u-1][0] = time
    while g.v_exists(u):
        for v in g.v:
            if (u,v) in g.e and g.v_color[v-1] == False:
                dfs(v)
    time += 1
    if ts[u-1][1] == 0:
        ts[u-1][1] = time dfs global time time += 1 time 1 g.color(u) g.color g color u if ts[u-1][0] == 0:
        ts[u-1][0] = time
     ts[u-1][0] == 0 ts[u-1][0] [u-1] ts u-1 u 1 0 0 ts[u-1][0] = time ts[u-1][0] [u-1] ts u-1 u 1 0 time while g.v_exists(u):
        for v in g.v:
            if (u,v) in g.e and g.v_color[v-1] == False:
                dfs(v)
     g.v_exists(u) g.v_exists g v_exists u for v in g.v:
            if (u,v) in g.e and g.v_color[v-1] == False:
                dfs(v)
     v g.v g v if (u,v) in g.e and g.v_color[v-1] == False:
                dfs(v)
     (u,v) in g.e and g.v_color[v-1] == False (u,v) in g.e (u,v) u v g.e g e g.v_color[v-1] == False g.v_color[v-1] g.v_color g v_color v-1 v 1 False dfs(v) dfs v time += 1 time 1 if ts[u-1][1] == 0:
        ts[u-1][1] = time ts[u-1][1] == 0 ts[u-1][1] [u-1] ts u-1 u 1 1 0 ts[u-1][1] = time ts[u-1][1] [u-1] ts u-1 u 1 1 time u u for i in range(N):
    if g.v_color[i] == False:
        dfs(i+1) i range(N) range N if g.v_color[i] == False:
        dfs(i+1) g.v_color[i] == False g.v_color[i] g.v_color g v_color i False dfs(i+1) dfs i+1 i 1 for i in range(N):
    print(i+1,ts[i][0],ts[i][1]) i range(N) range N print(i+1,ts[i][0],ts[i][1]) print i+1 i 1 ts[i][0] [i] ts i 0 ts[i][1] [i] ts i 1 N = int(input()) int(input()) N UK = [list(map(int,input().split())) for _ in range(N)] [list(map(int,input().split())) for _ in range(N)] UK def dfs(u):
    global time
    time += 1
    g.color(u)
    if ts[u-1][0] == 0:
        ts[u-1][0] = time
    while g.v_exists(u):
        for v in g.v:
            if (u,v) in g.e and g.v_color[v-1] == False:
                dfs(v)
    time += 1
    if ts[u-1][1] == 0:
        ts[u-1][1] = time def dfs(u):
    global time
    time += 1
    g.color(u)
    if ts[u-1][0] == 0:
        ts[u-1][0] = time
    while g.v_exists(u):
        for v in g.v:
            if (u,v) in g.e and g.v_color[v-1] == False:
                dfs(v)
    time += 1
    if ts[u-1][1] == 0:
        ts[u-1][1] = time dfs class Graph:
    def __init__(self,vertex,edge):
        self.v = vertex
        self.e = edge
        self.v_color = [False for _ in range(N)]

    def color(self,u):
        self.v_color[u-1] = True

    def v_exists(self,u):
        flag = False
        for v in self.v:
            if (u,v) in self.e and self.v_color[v-1] == False:
                flag = True
                break
        return flag class Graph:
    def __init__(self,vertex,edge):
        self.v = vertex
        self.e = edge
        self.v_color = [False for _ in range(N)]

    def color(self,u):
        self.v_color[u-1] = True

    def v_exists(self,u):
        flag = False
        for v in self.v:
            if (u,v) in self.e and self.v_color[v-1] == False:
                flag = True
                break
        return flag Graph g = Graph(V,E) Graph(V,E) g ts = [[0 for _ in range(2)] for _ in range(N+1)] [[0 for _ in range(2)] for _ in range(N+1)] ts E = [] [] E V = [i+1 for i in range(N)] [i+1 for i in range(N)] V time = 0 0 time
N = int(input())
UK = [list(map(int,input().split())) for _ in range(N)]

class Graph:
    def __init__(self,vertex,edge):
        self.v = vertex
        self.e = edge
        self.v_color = [False for _ in range(N)]

    def color(self,u):
        self.v_color[u-1] = True

    def v_exists(self,u):
        flag = False
        for v in self.v:
            if (u,v) in self.e and self.v_color[v-1] == False:
                flag = True
                break
        return flag

V = [i+1 for i in range(N)]
E = []
for i in range(N):
    for j in range(len(UK[i])-2):
        E.append((i+1,UK[i][j+2]))

g = Graph(V,E)

ts = [[0 for _ in range(2)] for _ in range(N+1)]
time = 0

def dfs(u):
    global time
    time += 1
    g.color(u)
    if ts[u-1][0] == 0:
        ts[u-1][0] = time
    while g.v_exists(u):
        for v in g.v:
            if (u,v) in g.e and g.v_color[v-1] == False:
                dfs(v)
    time += 1
    if ts[u-1][1] == 0:
        ts[u-1][1] = time

for i in range(N):
    if g.v_color[i] == False:
        dfs(i+1)

for i in range(N):
    print(i+1,ts[i][0],ts[i][1])

