#coding:utf-8
from copy import deepcopy

n = int(input())
c = ["white" for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
S = []
class DFS:
    def __init__(self, key, color="white",nex=None):
        self.color = color
        self.nex = nex
        self.key = key

objList = [DFS(i+1) for i in range(n)]
for i in range(n):
    data = list(map(int,input().split()))
    times = data[1]
    obj = objList[i]
    for j in range(times):
        index = data[2+j] - 1
        nextobj = DFS(index+1)
        obj.nex = nextobj
        obj = obj.nex


time = 1
def check(first,time):
    obj = objList[first]
    c[first] = "gray"
    d[first] = time
    f[first] = time
    S.append(first+1)
    
    while S != []:
        index = S[-1] - 1
        u = objList[index]
        v = u.nex
    
        if v != None:
            objList[index] = v
            if c[v.key - 1] == "white":
                index = v.key - 1
                v = objList[index]
                c[v.key-1] = "gray"
                time += 1
                d[index] = time
                S.append(v.key)

           
                
        else:
            S.pop()
            c[u.key-1] = "black"
            time += 1
            f[index] = time
    return time


for i in range(n):
    if f[i] == 0:
        time = check(i,time) + 1
        

k = 1
for i,j in zip(d,f):
    print(k,i,j)
    k += 1 from copy import deepcopy n = int(input()) n int(input()) int input() input "white" for i in range(n) for i in range(n) i range(n) range n for i in range(n) "white" c = ["white" for i in range(n)] c ["white" for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 d = [0 for i in range(n)] d [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 f = [0 for i in range(n)] f [0 for i in range(n)] S = [] S [] class DFS:
    def __init__(self, key, color="white",nex=None):
        self.color = color
        self.nex = nex
        self.key = key DFS def __init__(self, key, color="white",nex=None):
        self.color = color
        self.nex = nex
        self.key = key __init__ self.color = color self.color self color color self.nex = nex self.nex self nex nex self.key = key self.key self key key self self key key color="white" color "white" nex=None nex None DFS(i+1) for i in range(n) for i in range(n) i range(n) range n for i in range(n) DFS(i+1) DFS i+1 i 1 objList = [DFS(i+1) for i in range(n)] objList [DFS(i+1) for i in range(n)] for i in range(n):
    data = list(map(int,input().split()))
    times = data[1]
    obj = objList[i]
    for j in range(times):
        index = data[2+j] - 1
        nextobj = DFS(index+1)
        obj.nex = nextobj
        obj = obj.nex 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 times = data[1] times data[1] data 1 obj = objList[i] obj objList[i] objList i for j in range(times):
        index = data[2+j] - 1
        nextobj = DFS(index+1)
        obj.nex = nextobj
        obj = obj.nex j range(times) range times index = data[2+j] - 1 index data[2+j] - 1 data[2+j] data 2+j 2 j 1 nextobj = DFS(index+1) nextobj DFS(index+1) DFS index+1 index 1 obj.nex = nextobj obj.nex obj nex nextobj obj = obj.nex obj obj.nex obj nex time = 1 time 1 def check(first,time):
    obj = objList[first]
    c[first] = "gray"
    d[first] = time
    f[first] = time
    S.append(first+1)
    
    while S != []:
        index = S[-1] - 1
        u = objList[index]
        v = u.nex
    
        if v != None:
            objList[index] = v
            if c[v.key - 1] == "white":
                index = v.key - 1
                v = objList[index]
                c[v.key-1] = "gray"
                time += 1
                d[index] = time
                S.append(v.key)

           
                
        else:
            S.pop()
            c[u.key-1] = "black"
            time += 1
            f[index] = time
    return time check obj = objList[first] obj objList[first] objList first c[first] = "gray" c[first] c first "gray" d[first] = time d[first] d first time f[first] = time f[first] f first time S.append(first+1) S.append S append first+1 first 1 while S != []:
        index = S[-1] - 1
        u = objList[index]
        v = u.nex
    
        if v != None:
            objList[index] = v
            if c[v.key - 1] == "white":
                index = v.key - 1
                v = objList[index]
                c[v.key-1] = "gray"
                time += 1
                d[index] = time
                S.append(v.key)

           
                
        else:
            S.pop()
            c[u.key-1] = "black"
            time += 1
            f[index] = time
     S != [] S [] index = S[-1] - 1 index S[-1] - 1 S[-1] S -1 1 u = objList[index] u objList[index] objList index v = u.nex v u.nex u nex if v != None:
            objList[index] = v
            if c[v.key - 1] == "white":
                index = v.key - 1
                v = objList[index]
                c[v.key-1] = "gray"
                time += 1
                d[index] = time
                S.append(v.key)

           
                
        else:
            S.pop()
            c[u.key-1] = "black"
            time += 1
            f[index] = time
     v != None v None objList[index] = v objList[index] objList index v if c[v.key - 1] == "white":
                index = v.key - 1
                v = objList[index]
                c[v.key-1] = "gray"
                time += 1
                d[index] = time
                S.append(v.key)

           
                
         c[v.key - 1] == "white" c[v.key - 1] c v.key - 1 v.key v key 1 "white" index = v.key - 1 index v.key - 1 v.key v key 1 v = objList[index] v objList[index] objList index c[v.key-1] = "gray" c[v.key-1] c v.key-1 v.key v key 1 "gray" time += 1 time 1 d[index] = time d[index] d index time S.append(v.key) S.append S append v.key v key S.pop() S.pop S pop c[u.key-1] = "black" c[u.key-1] c u.key-1 u.key u key 1 "black" time += 1 time 1 f[index] = time f[index] f index time return time time first first time time for i in range(n):
    if f[i] == 0:
        time = check(i,time) + 1
         i range(n) range n if f[i] == 0:
        time = check(i,time) + 1
         f[i] == 0 f[i] f i 0 time = check(i,time) + 1 time check(i,time) + 1 check(i,time) check i time 1 k = 1 k 1 for i,j in zip(d,f):
    print(k,i,j)
    k += 1 i j zip(d,f) zip d f print(k,i,j) print k i j k += 1 k 1 time = 1 1 time f = [0 for i in range(n)] [0 for i in range(n)] f nextobj = DFS(index+1) DFS(index+1) nextobj time = check(i,time) + 1 check(i,time) + 1 time class DFS:
    def __init__(self, key, color="white",nex=None):
        self.color = color
        self.nex = nex
        self.key = key class DFS:
    def __init__(self, key, color="white",nex=None):
        self.color = color
        self.nex = nex
        self.key = key DFS objList = [DFS(i+1) for i in range(n)] [DFS(i+1) for i in range(n)] objList def check(first,time):
    obj = objList[first]
    c[first] = "gray"
    d[first] = time
    f[first] = time
    S.append(first+1)
    
    while S != []:
        index = S[-1] - 1
        u = objList[index]
        v = u.nex
    
        if v != None:
            objList[index] = v
            if c[v.key - 1] == "white":
                index = v.key - 1
                v = objList[index]
                c[v.key-1] = "gray"
                time += 1
                d[index] = time
                S.append(v.key)

           
                
        else:
            S.pop()
            c[u.key-1] = "black"
            time += 1
            f[index] = time
    return time def check(first,time):
    obj = objList[first]
    c[first] = "gray"
    d[first] = time
    f[first] = time
    S.append(first+1)
    
    while S != []:
        index = S[-1] - 1
        u = objList[index]
        v = u.nex
    
        if v != None:
            objList[index] = v
            if c[v.key - 1] == "white":
                index = v.key - 1
                v = objList[index]
                c[v.key-1] = "gray"
                time += 1
                d[index] = time
                S.append(v.key)

           
                
        else:
            S.pop()
            c[u.key-1] = "black"
            time += 1
            f[index] = time
    return time check k = 1 1 k index = data[2+j] - 1 data[2+j] - 1 index obj = obj.nex obj.nex obj c = ["white" for i in range(n)] ["white" for i in range(n)] c n = int(input()) int(input()) n d = [0 for i in range(n)] [0 for i in range(n)] d k += 1 1 k S = [] [] S data = list(map(int,input().split())) list(map(int,input().split())) data times = data[1] data[1] times obj = objList[i] objList[i] obj
#coding:utf-8
from copy import deepcopy

n = int(input())
c = ["white" for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
S = []
class DFS:
    def __init__(self, key, color="white",nex=None):
        self.color = color
        self.nex = nex
        self.key = key

objList = [DFS(i+1) for i in range(n)]
for i in range(n):
    data = list(map(int,input().split()))
    times = data[1]
    obj = objList[i]
    for j in range(times):
        index = data[2+j] - 1
        nextobj = DFS(index+1)
        obj.nex = nextobj
        obj = obj.nex


time = 1
def check(first,time):
    obj = objList[first]
    c[first] = "gray"
    d[first] = time
    f[first] = time
    S.append(first+1)
    
    while S != []:
        index = S[-1] - 1
        u = objList[index]
        v = u.nex
    
        if v != None:
            objList[index] = v
            if c[v.key - 1] == "white":
                index = v.key - 1
                v = objList[index]
                c[v.key-1] = "gray"
                time += 1
                d[index] = time
                S.append(v.key)

           
                
        else:
            S.pop()
            c[u.key-1] = "black"
            time += 1
            f[index] = time
    return time


for i in range(n):
    if f[i] == 0:
        time = check(i,time) + 1
        

k = 1
for i,j in zip(d,f):
    print(k,i,j)
    k += 1
