from __future__ import division,print_function
import time
import sys
import io
import re
import math
start = time.clock()
i = 0
def walk(index,tm,L,d,f):
    tm+=1
    d[index]=tm
    for i in L[index]:
        if not d[i-1]:
            tm=walk(i-1,tm,L,d,f)
    tm+=1
    f[index]=tm
    return tm
 
def main():
    num=int(sys.stdin.readline())
    L=[]
    for _ in range(num):
        L.append([int(s) for s in sys.stdin.readline().split()[2:]])
    d=[0]*num
    f=[0]*num
    tm=0
    for i in range(num):
        if not d[i]:
            tm=walk(i,tm,L,d,f)
    for i in range(num):
        print(i+1,d[i],f[i])
 
main() from __future__ import division,print_function import time time import sys sys import io io import re re import math math start = time.clock() start time.clock() time.clock time clock i = 0 i 0 def walk(index,tm,L,d,f):
    tm+=1
    d[index]=tm
    for i in L[index]:
        if not d[i-1]:
            tm=walk(i-1,tm,L,d,f)
    tm+=1
    f[index]=tm
    return tm
  walk tm+=1 tm 1 d[index]=tm d[index] d index tm for i in L[index]:
        if not d[i-1]:
            tm=walk(i-1,tm,L,d,f)
     i L[index] L index if not d[i-1]:
            tm=walk(i-1,tm,L,d,f)
     not d[i-1] d[i-1] d i-1 i 1 tm=walk(i-1,tm,L,d,f) tm walk(i-1,tm,L,d,f) walk i-1 i 1 tm L d f tm+=1 tm 1 f[index]=tm f[index] f index tm return tm tm index index tm tm L L d d f f def main():
    num=int(sys.stdin.readline())
    L=[]
    for _ in range(num):
        L.append([int(s) for s in sys.stdin.readline().split()[2:]])
    d=[0]*num
    f=[0]*num
    tm=0
    for i in range(num):
        if not d[i]:
            tm=walk(i,tm,L,d,f)
    for i in range(num):
        print(i+1,d[i],f[i])
  main num=int(sys.stdin.readline()) num int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline L=[] L [] for _ in range(num):
        L.append([int(s) for s in sys.stdin.readline().split()[2:]])
     _ range(num) range num int(s) for s in sys.stdin.readline().split()[2:] for s in sys.stdin.readline().split()[2:] s sys.stdin.readline().split()[2:] sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split 2: 2 for s in sys.stdin.readline().split()[2:] int(s) int s L.append([int(s) for s in sys.stdin.readline().split()[2:]]) L.append L append [int(s) for s in sys.stdin.readline().split()[2:]] d=[0]*num d [0]*num [0] 0 num f=[0]*num f [0]*num [0] 0 num tm=0 tm 0 for i in range(num):
        if not d[i]:
            tm=walk(i,tm,L,d,f)
     i range(num) range num if not d[i]:
            tm=walk(i,tm,L,d,f)
     not d[i] d[i] d i tm=walk(i,tm,L,d,f) tm walk(i,tm,L,d,f) walk i tm L d f for i in range(num):
        print(i+1,d[i],f[i])
  i range(num) range num print(i+1,d[i],f[i]) print i+1 i 1 d[i] d i f[i] f i main() main def main():
    num=int(sys.stdin.readline())
    L=[]
    for _ in range(num):
        L.append([int(s) for s in sys.stdin.readline().split()[2:]])
    d=[0]*num
    f=[0]*num
    tm=0
    for i in range(num):
        if not d[i]:
            tm=walk(i,tm,L,d,f)
    for i in range(num):
        print(i+1,d[i],f[i])
  def main():
    num=int(sys.stdin.readline())
    L=[]
    for _ in range(num):
        L.append([int(s) for s in sys.stdin.readline().split()[2:]])
    d=[0]*num
    f=[0]*num
    tm=0
    for i in range(num):
        if not d[i]:
            tm=walk(i,tm,L,d,f)
    for i in range(num):
        print(i+1,d[i],f[i])
  main i = 0 0 i start = time.clock() time.clock() start def walk(index,tm,L,d,f):
    tm+=1
    d[index]=tm
    for i in L[index]:
        if not d[i-1]:
            tm=walk(i-1,tm,L,d,f)
    tm+=1
    f[index]=tm
    return tm
  def walk(index,tm,L,d,f):
    tm+=1
    d[index]=tm
    for i in L[index]:
        if not d[i-1]:
            tm=walk(i-1,tm,L,d,f)
    tm+=1
    f[index]=tm
    return tm
  walk
from __future__ import division,print_function
import time
import sys
import io
import re
import math
start = time.clock()
i = 0
def walk(index,tm,L,d,f):
    tm+=1
    d[index]=tm
    for i in L[index]:
        if not d[i-1]:
            tm=walk(i-1,tm,L,d,f)
    tm+=1
    f[index]=tm
    return tm
 
def main():
    num=int(sys.stdin.readline())
    L=[]
    for _ in range(num):
        L.append([int(s) for s in sys.stdin.readline().split()[2:]])
    d=[0]*num
    f=[0]*num
    tm=0
    for i in range(num):
        if not d[i]:
            tm=walk(i,tm,L,d,f)
    for i in range(num):
        print(i+1,d[i],f[i])
 
main()