# coding: utf-8
timestamp = 1

stack = []
indata = []
visit = []      #?¨?????¨????
visitTime = []  #?¨???????????¨??????¨
lastTimeStack = []      #?¨?????????????????¨??????¨


def inputdata():
    global      visit
    global      indata
    global      visitTime

    n = int(input().rstrip())

    for i in range(n):
        visit.append(True)
        visitTime.append([0, 0])

        lst = [int(i) for i in input().rstrip().split(" ")]
        k = lst[1]
        v = []
        for j in range(k):
            v.append(lst[2 + j] - 1)
        indata.append(v)

def procV(n):
    global lastTimeStack
    global timestamp
    global visit
    global stack

    if visit[n]:
        stack.append(n)
        lastTimeStack.append(n)
        visitTime[n][0] = timestamp
        timestamp += 1
        visit[n] = False
    else:
        if visitTime[n][1] == 0:
            visitTime[n][1] = timestamp
            timestamp += 1

"""
main
"""
inputdata()
stack.append(0)             #?????????????´????push??????

while True:
    if len(stack) == 0:
        isNotVisit = True
        n = 0
        for i in visit:
            if i:
                isNotVisit = False
                stack.append(n)
                break
            n += 1
        if isNotVisit:
            break

    n = stack.pop()         #??????????????????pop??????
    procV(n)                #pop????????????????????????????????????

    #???????????¢???
    for i in reversed(indata[n]):
        if visit[i]:
            hasNotChildAdd = False
            stack.append(i)

i = 1
for val in visitTime:
    li = [i, val[0], val[1]]
    print(' '.join(map(str, li)))
    i += 1 timestamp = 1 timestamp 1 stack = [] stack [] indata = [] indata [] visit = [] visit [] visitTime = [] visitTime [] lastTimeStack = [] lastTimeStack [] def inputdata():
    global      visit
    global      indata
    global      visitTime

    n = int(input().rstrip())

    for i in range(n):
        visit.append(True)
        visitTime.append([0, 0])

        lst = [int(i) for i in input().rstrip().split(" ")]
        k = lst[1]
        v = []
        for j in range(k):
            v.append(lst[2 + j] - 1)
        indata.append(v) inputdata global      visit global      indata global      visitTime n = int(input().rstrip()) n int(input().rstrip()) int input().rstrip() ().rstrip () input rstrip for i in range(n):
        visit.append(True)
        visitTime.append([0, 0])

        lst = [int(i) for i in input().rstrip().split(" ")]
        k = lst[1]
        v = []
        for j in range(k):
            v.append(lst[2 + j] - 1)
        indata.append(v) i range(n) range n visit.append(True) visit.append visit append True visitTime.append([0, 0]) visitTime.append visitTime append [0, 0] 0 0 int(i) for i in input().rstrip().split(" ") for i in input().rstrip().split(" ") i input().rstrip().split(" ") ().rstrip().split ().rstrip() ().rstrip () input rstrip split " " for i in input().rstrip().split(" ") int(i) int i lst = [int(i) for i in input().rstrip().split(" ")] lst [int(i) for i in input().rstrip().split(" ")] k = lst[1] k lst[1] lst 1 v = [] v [] for j in range(k):
            v.append(lst[2 + j] - 1)
         j range(k) range k v.append(lst[2 + j] - 1) v.append v append lst[2 + j] - 1 lst[2 + j] lst 2 + j 2 j 1 indata.append(v) indata.append indata append v def procV(n):
    global lastTimeStack
    global timestamp
    global visit
    global stack

    if visit[n]:
        stack.append(n)
        lastTimeStack.append(n)
        visitTime[n][0] = timestamp
        timestamp += 1
        visit[n] = False
    else:
        if visitTime[n][1] == 0:
            visitTime[n][1] = timestamp
            timestamp += 1 procV global lastTimeStack global timestamp global visit global stack if visit[n]:
        stack.append(n)
        lastTimeStack.append(n)
        visitTime[n][0] = timestamp
        timestamp += 1
        visit[n] = False
    else:
        if visitTime[n][1] == 0:
            visitTime[n][1] = timestamp
            timestamp += 1 visit[n] visit n stack.append(n) stack.append stack append n lastTimeStack.append(n) lastTimeStack.append lastTimeStack append n visitTime[n][0] = timestamp visitTime[n][0] [n] visitTime n 0 timestamp timestamp += 1 timestamp 1 visit[n] = False visit[n] visit n False if visitTime[n][1] == 0:
            visitTime[n][1] = timestamp
            timestamp += 1 visitTime[n][1] == 0 visitTime[n][1] [n] visitTime n 1 0 visitTime[n][1] = timestamp visitTime[n][1] [n] visitTime n 1 timestamp timestamp += 1 timestamp 1 n n """
main
""" inputdata() inputdata stack.append(0) stack.append stack append 0 while True:
    if len(stack) == 0:
        isNotVisit = True
        n = 0
        for i in visit:
            if i:
                isNotVisit = False
                stack.append(n)
                break
            n += 1
        if isNotVisit:
            break

    n = stack.pop()         #??????????????????pop??????
    procV(n)                #pop????????????????????????????????????

    #???????????¢???
    for i in reversed(indata[n]):
        if visit[i]:
            hasNotChildAdd = False
            stack.append(i) True if len(stack) == 0:
        isNotVisit = True
        n = 0
        for i in visit:
            if i:
                isNotVisit = False
                stack.append(n)
                break
            n += 1
        if isNotVisit:
            break

     len(stack) == 0 len(stack) len stack 0 isNotVisit = True isNotVisit True n = 0 n 0 for i in visit:
            if i:
                isNotVisit = False
                stack.append(n)
                break
            n += 1
         i visit if i:
                isNotVisit = False
                stack.append(n)
                break
             i isNotVisit = False isNotVisit False stack.append(n) stack.append stack append n break n += 1 n 1 if isNotVisit:
            break

     isNotVisit break n = stack.pop() n stack.pop() stack.pop stack pop procV(n) procV n for i in reversed(indata[n]):
        if visit[i]:
            hasNotChildAdd = False
            stack.append(i) i reversed(indata[n]) reversed indata[n] indata n if visit[i]:
            hasNotChildAdd = False
            stack.append(i) visit[i] visit i hasNotChildAdd = False hasNotChildAdd False stack.append(i) stack.append stack append i i = 1 i 1 for val in visitTime:
    li = [i, val[0], val[1]]
    print(' '.join(map(str, li)))
    i += 1 val visitTime li = [i, val[0], val[1]] li [i, val[0], val[1]] i val[0] val 0 val[1] val 1 print(' '.join(map(str, li))) print ' '.join(map(str, li)) ' '.join ' ' join map(str, li) map str li i += 1 i 1 hasNotChildAdd = False False hasNotChildAdd timestamp = 1 1 timestamp visit = [] [] visit def procV(n):
    global lastTimeStack
    global timestamp
    global visit
    global stack

    if visit[n]:
        stack.append(n)
        lastTimeStack.append(n)
        visitTime[n][0] = timestamp
        timestamp += 1
        visit[n] = False
    else:
        if visitTime[n][1] == 0:
            visitTime[n][1] = timestamp
            timestamp += 1 def procV(n):
    global lastTimeStack
    global timestamp
    global visit
    global stack

    if visit[n]:
        stack.append(n)
        lastTimeStack.append(n)
        visitTime[n][0] = timestamp
        timestamp += 1
        visit[n] = False
    else:
        if visitTime[n][1] == 0:
            visitTime[n][1] = timestamp
            timestamp += 1 procV isNotVisit = False False isNotVisit n = stack.pop() stack.pop() n i = 1 1 i li = [i, val[0], val[1]] [i, val[0], val[1]] li indata = [] [] indata visitTime = [] [] visitTime stack = [] [] stack lastTimeStack = [] [] lastTimeStack isNotVisit = True True isNotVisit n = 0 0 n n += 1 1 n i += 1 1 i def inputdata():
    global      visit
    global      indata
    global      visitTime

    n = int(input().rstrip())

    for i in range(n):
        visit.append(True)
        visitTime.append([0, 0])

        lst = [int(i) for i in input().rstrip().split(" ")]
        k = lst[1]
        v = []
        for j in range(k):
            v.append(lst[2 + j] - 1)
        indata.append(v) def inputdata():
    global      visit
    global      indata
    global      visitTime

    n = int(input().rstrip())

    for i in range(n):
        visit.append(True)
        visitTime.append([0, 0])

        lst = [int(i) for i in input().rstrip().split(" ")]
        k = lst[1]
        v = []
        for j in range(k):
            v.append(lst[2 + j] - 1)
        indata.append(v) inputdata
# coding: utf-8
timestamp = 1

stack = []
indata = []
visit = []      #?¨?????¨????
visitTime = []  #?¨???????????¨??????¨
lastTimeStack = []      #?¨?????????????????¨??????¨


def inputdata():
    global      visit
    global      indata
    global      visitTime

    n = int(input().rstrip())

    for i in range(n):
        visit.append(True)
        visitTime.append([0, 0])

        lst = [int(i) for i in input().rstrip().split(" ")]
        k = lst[1]
        v = []
        for j in range(k):
            v.append(lst[2 + j] - 1)
        indata.append(v)

def procV(n):
    global lastTimeStack
    global timestamp
    global visit
    global stack

    if visit[n]:
        stack.append(n)
        lastTimeStack.append(n)
        visitTime[n][0] = timestamp
        timestamp += 1
        visit[n] = False
    else:
        if visitTime[n][1] == 0:
            visitTime[n][1] = timestamp
            timestamp += 1

"""
main
"""
inputdata()
stack.append(0)             #?????????????´????push??????

while True:
    if len(stack) == 0:
        isNotVisit = True
        n = 0
        for i in visit:
            if i:
                isNotVisit = False
                stack.append(n)
                break
            n += 1
        if isNotVisit:
            break

    n = stack.pop()         #??????????????????pop??????
    procV(n)                #pop????????????????????????????????????

    #???????????¢???
    for i in reversed(indata[n]):
        if visit[i]:
            hasNotChildAdd = False
            stack.append(i)

i = 1
for val in visitTime:
    li = [i, val[0], val[1]]
    print(' '.join(map(str, li)))
    i += 1