# -*- coding: utf-8 -*-
"""
Created on Sun Jul  8 10:56:33 2018

@author: maezawa
"""
n = int(input())
adj = [[] for _ in range(n)]
d = [0 for _ in range(n)]
f = [0 for _ in range(n)]

for j in range(n):
    ain = list(map(int, input().split()))
    u = ain[0]
    k = ain[1]
    for i in range(k):
        adj[u-1].append(ain[i+2]-1)
    adj[u-1].sort()
    #print(*adj[u-1])

t = 1

for j in range(n):
    if d[j] == 0:
        stack = [j]

    while stack:
        #print(stack)
        current = stack[-1]
        if d[current] == 0:
            d[current] = t
            t += 1
        flag = 0
        for k in adj[current]:
            if d[k] == 0:
                stack.append(k)
                flag = 1
                break
        if flag == 0:
            f[current] = t
            t += 1
            stack.pop()

    #print('current = {}, t = {}'.format(current, t))
    #print('stack', *stack)

for i in range(n):
    print('{} {} {}'.format(i+1, d[i], f[i]))
 """
Created on Sun Jul  8 10:56:33 2018

@author: maezawa
""" n = int(input()) n int(input()) int input() input [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] adj = [[] for _ in range(n)] adj [[] for _ in range(n)] 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 d = [0 for _ in range(n)] d [0 for _ in range(n)] 0 for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) 0 f = [0 for _ in range(n)] f [0 for _ in range(n)] for j in range(n):
    ain = list(map(int, input().split()))
    u = ain[0]
    k = ain[1]
    for i in range(k):
        adj[u-1].append(ain[i+2]-1)
    adj[u-1].sort()
    #print(*adj[u-1]) j range(n) range n ain = list(map(int, input().split())) ain list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split u = ain[0] u ain[0] ain 0 k = ain[1] k ain[1] ain 1 for i in range(k):
        adj[u-1].append(ain[i+2]-1)
     i range(k) range k adj[u-1].append(ain[i+2]-1) [u-1].append [u-1] adj u-1 u 1 append ain[i+2]-1 ain[i+2] ain i+2 i 2 1 adj[u-1].sort() [u-1].sort [u-1] adj u-1 u 1 sort t = 1 t 1 for j in range(n):
    if d[j] == 0:
        stack = [j]

    while stack:
        #print(stack)
        current = stack[-1]
        if d[current] == 0:
            d[current] = t
            t += 1
        flag = 0
        for k in adj[current]:
            if d[k] == 0:
                stack.append(k)
                flag = 1
                break
        if flag == 0:
            f[current] = t
            t += 1
            stack.pop()

    #print('current = {}, t = {}'.format(current, t))
    #print('stack', *stack) j range(n) range n if d[j] == 0:
        stack = [j]

     d[j] == 0 d[j] d j 0 stack = [j] stack [j] j while stack:
        #print(stack)
        current = stack[-1]
        if d[current] == 0:
            d[current] = t
            t += 1
        flag = 0
        for k in adj[current]:
            if d[k] == 0:
                stack.append(k)
                flag = 1
                break
        if flag == 0:
            f[current] = t
            t += 1
            stack.pop()

    #print('current = {}, t = {}'.format(current, t))
    #print('stack', *stack) stack current = stack[-1] current stack[-1] stack -1 if d[current] == 0:
            d[current] = t
            t += 1
         d[current] == 0 d[current] d current 0 d[current] = t d[current] d current t t += 1 t 1 flag = 0 flag 0 for k in adj[current]:
            if d[k] == 0:
                stack.append(k)
                flag = 1
                break
         k adj[current] adj current if d[k] == 0:
                stack.append(k)
                flag = 1
                break
         d[k] == 0 d[k] d k 0 stack.append(k) stack.append stack append k flag = 1 flag 1 break if flag == 0:
            f[current] = t
            t += 1
            stack.pop()

    #print('current = {}, t = {}'.format(current, t))
    #print('stack', *stack) flag == 0 flag 0 f[current] = t f[current] f current t t += 1 t 1 stack.pop() stack.pop stack pop for i in range(n):
    print('{} {} {}'.format(i+1, d[i], f[i])) i range(n) range n print('{} {} {}'.format(i+1, d[i], f[i])) print '{} {} {}'.format(i+1, d[i], f[i]) '{} {} {}'.format '{} {} {}' format i+1 i 1 d[i] d i f[i] f i stack = [j] [j] stack k = ain[1] ain[1] k n = int(input()) int(input()) n adj = [[] for _ in range(n)] [[] for _ in range(n)] adj t += 1 1 t d = [0 for _ in range(n)] [0 for _ in range(n)] d t = 1 1 t t += 1 1 t f = [0 for _ in range(n)] [0 for _ in range(n)] f current = stack[-1] stack[-1] current u = ain[0] ain[0] u flag = 0 0 flag flag = 1 1 flag ain = list(map(int, input().split())) list(map(int, input().split())) ain
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  8 10:56:33 2018

@author: maezawa
"""
n = int(input())
adj = [[] for _ in range(n)]
d = [0 for _ in range(n)]
f = [0 for _ in range(n)]

for j in range(n):
    ain = list(map(int, input().split()))
    u = ain[0]
    k = ain[1]
    for i in range(k):
        adj[u-1].append(ain[i+2]-1)
    adj[u-1].sort()
    #print(*adj[u-1])

t = 1

for j in range(n):
    if d[j] == 0:
        stack = [j]

    while stack:
        #print(stack)
        current = stack[-1]
        if d[current] == 0:
            d[current] = t
            t += 1
        flag = 0
        for k in adj[current]:
            if d[k] == 0:
                stack.append(k)
                flag = 1
                break
        if flag == 0:
            f[current] = t
            t += 1
            stack.pop()

    #print('current = {}, t = {}'.format(current, t))
    #print('stack', *stack)

for i in range(n):
    print('{} {} {}'.format(i+1, d[i], f[i]))

