time = 0

def dfs_visit(g, u):
    global time
    time += 1
    u[2] = time
    u[1] = 'g'

    for v in u[0]:
        ch = g[v]
        if ch[1] == 'w':
            ch[4] = u[5]
            dfs_visit(g, ch)
    u[1] = 'b'
    time += 1
    u[3] = time

n = int(input())

g = {}
s = 0
stack = []
for i in range(n):
    x = list(map(int, input().split()))
    g[x[0]] = [x[2:], 'w', 0, 0, None, x[0]]
    if i == 0:
        s = x[0]

for k, v in g.items():
    if v[1] == 'w':
        dfs_visit(g, v)


for i in range(n):
    node = g[i+1]
    print("{} {} {}".format(i+1, node[2], node[3])) time = 0 time 0 def dfs_visit(g, u):
    global time
    time += 1
    u[2] = time
    u[1] = 'g'

    for v in u[0]:
        ch = g[v]
        if ch[1] == 'w':
            ch[4] = u[5]
            dfs_visit(g, ch)
    u[1] = 'b'
    time += 1
    u[3] = time dfs_visit global time time += 1 time 1 u[2] = time u[2] u 2 time u[1] = 'g' u[1] u 1 'g' for v in u[0]:
        ch = g[v]
        if ch[1] == 'w':
            ch[4] = u[5]
            dfs_visit(g, ch)
     v u[0] u 0 ch = g[v] ch g[v] g v if ch[1] == 'w':
            ch[4] = u[5]
            dfs_visit(g, ch)
     ch[1] == 'w' ch[1] ch 1 'w' ch[4] = u[5] ch[4] ch 4 u[5] u 5 dfs_visit(g, ch) dfs_visit g ch u[1] = 'b' u[1] u 1 'b' time += 1 time 1 u[3] = time u[3] u 3 time g g u u n = int(input()) n int(input()) int input() input g = {} g {} s = 0 s 0 stack = [] stack [] for i in range(n):
    x = list(map(int, input().split()))
    g[x[0]] = [x[2:], 'w', 0, 0, None, x[0]]
    if i == 0:
        s = x[0] i range(n) range n x = list(map(int, input().split())) x list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split g[x[0]] = [x[2:], 'w', 0, 0, None, x[0]] g[x[0]] g x[0] x 0 [x[2:], 'w', 0, 0, None, x[0]] x[2:] x 2: 2 'w' 0 0 None x[0] x 0 if i == 0:
        s = x[0] i == 0 i 0 s = x[0] s x[0] x 0 for k, v in g.items():
    if v[1] == 'w':
        dfs_visit(g, v) k v g.items() g.items g items if v[1] == 'w':
        dfs_visit(g, v) v[1] == 'w' v[1] v 1 'w' dfs_visit(g, v) dfs_visit g v for i in range(n):
    node = g[i+1]
    print("{} {} {}".format(i+1, node[2], node[3])) i range(n) range n node = g[i+1] node g[i+1] g i+1 i 1 print("{} {} {}".format(i+1, node[2], node[3])) print "{} {} {}".format(i+1, node[2], node[3]) "{} {} {}".format "{} {} {}" format i+1 i 1 node[2] node 2 node[3] node 3 g = {} {} g time = 0 0 time n = int(input()) int(input()) n s = x[0] x[0] s def dfs_visit(g, u):
    global time
    time += 1
    u[2] = time
    u[1] = 'g'

    for v in u[0]:
        ch = g[v]
        if ch[1] == 'w':
            ch[4] = u[5]
            dfs_visit(g, ch)
    u[1] = 'b'
    time += 1
    u[3] = time def dfs_visit(g, u):
    global time
    time += 1
    u[2] = time
    u[1] = 'g'

    for v in u[0]:
        ch = g[v]
        if ch[1] == 'w':
            ch[4] = u[5]
            dfs_visit(g, ch)
    u[1] = 'b'
    time += 1
    u[3] = time dfs_visit s = 0 0 s stack = [] [] stack node = g[i+1] g[i+1] node x = list(map(int, input().split())) list(map(int, input().split())) x
time = 0

def dfs_visit(g, u):
    global time
    time += 1
    u[2] = time
    u[1] = 'g'

    for v in u[0]:
        ch = g[v]
        if ch[1] == 'w':
            ch[4] = u[5]
            dfs_visit(g, ch)
    u[1] = 'b'
    time += 1
    u[3] = time

n = int(input())

g = {}
s = 0
stack = []
for i in range(n):
    x = list(map(int, input().split()))
    g[x[0]] = [x[2:], 'w', 0, 0, None, x[0]]
    if i == 0:
        s = x[0]

for k, v in g.items():
    if v[1] == 'w':
        dfs_visit(g, v)


for i in range(n):
    node = g[i+1]
    print("{} {} {}".format(i+1, node[2], node[3]))