global t
t = 0

class Node:
    def __init__(self, num, deg, neib):
        self.num = num
        self.deg = deg
        self.neib = neib

def dfs(G, d, f, now): #now:1,2,...
    #print("now:",now)
    global t
    t += 1
    #print("t:",t)
    if d[now-1] != 0:
        t -= 1
        #print("has searched or hit roop")
    else:
        d[now-1] = t
        #print("d:",d)
        #print("f:",f)
        for i in G[now-1].neib:
            #print("i:",i)
            if i != -1:
                #print("next node")
                dfs(G, d, f, i)
            #else: print("end of branch")
        t += 1
        f[now-1] = t

        #print("f:",f)


dnum = int(input()) #頂点数
N = []
for i in range(dnum):
    data = input().split()
    
    u = int(data[0])
    k = int(data[1])
    if k > 0:
        v = list(map(int, data[2:]))
    else:
        v = [-1]

    node = Node(u,k,v)
    N.append(node)

d = [0]*dnum #find time
f = [0]*dnum #finish time

while 0 in d:
    s = d.index(0)
    dfs(N, d, f, s+1)
    #print("looks like finish")

for i in range(dnum):
    print(i+1, d[i], f[i])
 global t t = 0 t 0 class Node:
    def __init__(self, num, deg, neib):
        self.num = num
        self.deg = deg
        self.neib = neib Node def __init__(self, num, deg, neib):
        self.num = num
        self.deg = deg
        self.neib = neib __init__ self.num = num self.num self num num self.deg = deg self.deg self deg deg self.neib = neib self.neib self neib neib self self num num deg deg neib neib def dfs(G, d, f, now): #now:1,2,...
    #print("now:",now)
    global t
    t += 1
    #print("t:",t)
    if d[now-1] != 0:
        t -= 1
        #print("has searched or hit roop")
    else:
        d[now-1] = t
        #print("d:",d)
        #print("f:",f)
        for i in G[now-1].neib:
            #print("i:",i)
            if i != -1:
                #print("next node")
                dfs(G, d, f, i)
            #else: print("end of branch")
        t += 1
        f[now-1] = t

        #print("f:",f) dfs global t t += 1 t 1 if d[now-1] != 0:
        t -= 1
        #print("has searched or hit roop")
    else:
        d[now-1] = t
        #print("d:",d)
        #print("f:",f)
        for i in G[now-1].neib:
            #print("i:",i)
            if i != -1:
                #print("next node")
                dfs(G, d, f, i)
            #else: print("end of branch")
        t += 1
        f[now-1] = t

        #print("f:",f) d[now-1] != 0 d[now-1] d now-1 now 1 0 t -= 1 t 1 d[now-1] = t d[now-1] d now-1 now 1 t for i in G[now-1].neib:
            #print("i:",i)
            if i != -1:
                #print("next node")
                dfs(G, d, f, i)
            #else: print("end of branch")
         i G[now-1].neib [now-1] G now-1 now 1 neib if i != -1:
                #print("next node")
                dfs(G, d, f, i)
            #else: print("end of branch")
         i != -1 i -1 dfs(G, d, f, i) dfs G d f i t += 1 t 1 f[now-1] = t f[now-1] f now-1 now 1 t G G d d f f now now dnum = int(input()) dnum int(input()) int input() input N = [] N [] for i in range(dnum):
    data = input().split()
    
    u = int(data[0])
    k = int(data[1])
    if k > 0:
        v = list(map(int, data[2:]))
    else:
        v = [-1]

    node = Node(u,k,v)
    N.append(node) i range(dnum) range dnum data = input().split() data input().split() ().split () input split u = int(data[0]) u int(data[0]) int data[0] data 0 k = int(data[1]) k int(data[1]) int data[1] data 1 if k > 0:
        v = list(map(int, data[2:]))
    else:
        v = [-1]

     k > 0 k 0 v = list(map(int, data[2:])) v list(map(int, data[2:])) list map(int, data[2:]) map int data[2:] data 2: 2 v = [-1] v [-1] -1 node = Node(u,k,v) node Node(u,k,v) Node u k v N.append(node) N.append N append node d = [0]*dnum d [0]*dnum [0] 0 dnum f = [0]*dnum f [0]*dnum [0] 0 dnum while 0 in d:
    s = d.index(0)
    dfs(N, d, f, s+1)
    #print("looks like finish") 0 in d 0 d s = d.index(0) s d.index(0) d.index d index 0 dfs(N, d, f, s+1) dfs N d f s+1 s 1 for i in range(dnum):
    print(i+1, d[i], f[i]) i range(dnum) range dnum print(i+1, d[i], f[i]) print i+1 i 1 d[i] d i f[i] f i k = int(data[1]) int(data[1]) k u = int(data[0]) int(data[0]) u node = Node(u,k,v) Node(u,k,v) node dnum = int(input()) int(input()) dnum d = [0]*dnum [0]*dnum d s = d.index(0) d.index(0) s data = input().split() input().split() data f = [0]*dnum [0]*dnum f N = [] [] N t = 0 0 t v = [-1] [-1] v global t v = list(map(int, data[2:])) list(map(int, data[2:])) v class Node:
    def __init__(self, num, deg, neib):
        self.num = num
        self.deg = deg
        self.neib = neib class Node:
    def __init__(self, num, deg, neib):
        self.num = num
        self.deg = deg
        self.neib = neib Node def dfs(G, d, f, now): #now:1,2,...
    #print("now:",now)
    global t
    t += 1
    #print("t:",t)
    if d[now-1] != 0:
        t -= 1
        #print("has searched or hit roop")
    else:
        d[now-1] = t
        #print("d:",d)
        #print("f:",f)
        for i in G[now-1].neib:
            #print("i:",i)
            if i != -1:
                #print("next node")
                dfs(G, d, f, i)
            #else: print("end of branch")
        t += 1
        f[now-1] = t

        #print("f:",f) def dfs(G, d, f, now): #now:1,2,...
    #print("now:",now)
    global t
    t += 1
    #print("t:",t)
    if d[now-1] != 0:
        t -= 1
        #print("has searched or hit roop")
    else:
        d[now-1] = t
        #print("d:",d)
        #print("f:",f)
        for i in G[now-1].neib:
            #print("i:",i)
            if i != -1:
                #print("next node")
                dfs(G, d, f, i)
            #else: print("end of branch")
        t += 1
        f[now-1] = t

        #print("f:",f) dfs
global t
t = 0

class Node:
    def __init__(self, num, deg, neib):
        self.num = num
        self.deg = deg
        self.neib = neib

def dfs(G, d, f, now): #now:1,2,...
    #print("now:",now)
    global t
    t += 1
    #print("t:",t)
    if d[now-1] != 0:
        t -= 1
        #print("has searched or hit roop")
    else:
        d[now-1] = t
        #print("d:",d)
        #print("f:",f)
        for i in G[now-1].neib:
            #print("i:",i)
            if i != -1:
                #print("next node")
                dfs(G, d, f, i)
            #else: print("end of branch")
        t += 1
        f[now-1] = t

        #print("f:",f)


dnum = int(input()) #頂点数
N = []
for i in range(dnum):
    data = input().split()
    
    u = int(data[0])
    k = int(data[1])
    if k > 0:
        v = list(map(int, data[2:]))
    else:
        v = [-1]

    node = Node(u,k,v)
    N.append(node)

d = [0]*dnum #find time
f = [0]*dnum #finish time

while 0 in d:
    s = d.index(0)
    dfs(N, d, f, s+1)
    #print("looks like finish")

for i in range(dnum):
    print(i+1, d[i], f[i])

