n=0
m=input()
c=[0 for i in xrange(m)]
t=[0 for i in xrange(m)]


def d(u):
    global n
    if t[u]:return
    n = n + 1
    t[u]=[u+1,n]
    for i in c[u]:d(i-1)
    n = n + 1
    t[u][2:]=[n]

def dfs():
    for i in range(m):
     l=map(int,raw_input().split())
     c[l[0]-1]=l[2:]
    for i in range(m):
     d(i)
     print " ".join(map(str,t[i]))

dfs() n=0 n 0 m=input() m input() input 0 for i in xrange(m) for i in xrange(m) i xrange(m) xrange m for i in xrange(m) 0 c=[0 for i in xrange(m)] c [0 for i in xrange(m)] 0 for i in xrange(m) for i in xrange(m) i xrange(m) xrange m for i in xrange(m) 0 t=[0 for i in xrange(m)] t [0 for i in xrange(m)] def d(u):
    global n
    if t[u]:return
    n = n + 1
    t[u]=[u+1,n]
    for i in c[u]:d(i-1)
    n = n + 1
    t[u][2:]=[n] d global n if t[u]:return
     t[u] t u n = n + 1 n n + 1 n 1 t[u]=[u+1,n] t[u] t u [u+1,n] u+1 u 1 n for i in c[u]:d(i-1)
     i c[u] c u n = n + 1 n n + 1 n 1 t[u][2:]=[n] t[u][2:] [u] t u 2: 2 [n] n u u def dfs():
    for i in range(m):
     l=map(int,raw_input().split())
     c[l[0]-1]=l[2:]
    for i in range(m):
     d(i)
     print " ".join(map(str,t[i])) dfs for i in range(m):
     l=map(int,raw_input().split())
     c[l[0]-1]=l[2:]
     i range(m) range m l=map(int,raw_input().split()) l map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split c[l[0]-1]=l[2:] c[l[0]-1] c l[0]-1 l[0] l 0 1 l[2:] l 2: 2 for i in range(m):
     d(i)
     print " ".join(map(str,t[i])) i range(m) range m d(i) d i print " ".join(map(str,t[i])) " ".join " " join map(str,t[i]) map str t[i] t i dfs() dfs c=[0 for i in xrange(m)] [0 for i in xrange(m)] c n=0 0 n m=input() input() m def d(u):
    global n
    if t[u]:return
    n = n + 1
    t[u]=[u+1,n]
    for i in c[u]:d(i-1)
    n = n + 1
    t[u][2:]=[n] def d(u):
    global n
    if t[u]:return
    n = n + 1
    t[u]=[u+1,n]
    for i in c[u]:d(i-1)
    n = n + 1
    t[u][2:]=[n] d t=[0 for i in xrange(m)] [0 for i in xrange(m)] t def dfs():
    for i in range(m):
     l=map(int,raw_input().split())
     c[l[0]-1]=l[2:]
    for i in range(m):
     d(i)
     print " ".join(map(str,t[i])) def dfs():
    for i in range(m):
     l=map(int,raw_input().split())
     c[l[0]-1]=l[2:]
    for i in range(m):
     d(i)
     print " ".join(map(str,t[i])) dfs
n=0
m=input()
c=[0 for i in xrange(m)]
t=[0 for i in xrange(m)]


def d(u):
    global n
    if t[u]:return
    n = n + 1
    t[u]=[u+1,n]
    for i in c[u]:d(i-1)
    n = n + 1
    t[u][2:]=[n]

def dfs():
    for i in range(m):
     l=map(int,raw_input().split())
     c[l[0]-1]=l[2:]
    for i in range(m):
     d(i)
     print " ".join(map(str,t[i]))

dfs()