import sys

global stamp, counter
stamp = {}
counter = 0

def dfs(key, GRAPH):
    global stamp, counter
    if stamp[key][0] == 0:
        counter += 1
        stamp[key][0] = counter
    elif stamp[key][1] != 0:
        return

    for e in GRAPH[key]:
        try:
            if stamp[e][0] == 0:
                dfs(e, GRAPH)
        except:
            pass
    counter += 1
    stamp[key][1] = counter
    return

n = int(raw_input())
x = {}
for i in range(n):
    seq = map(int, raw_input().split())
    key = seq[0]
    if key != 0:
        x[key] = seq[2:]
    else:
        x[key] = []  
    stamp[key] = [0, 0]

for e in x.keys():
    dfs(e, x)

for e in x.keys():
    print e, stamp[e][0], stamp[e][1] import sys sys global stamp, counter stamp = {} stamp {} counter = 0 counter 0 def dfs(key, GRAPH):
    global stamp, counter
    if stamp[key][0] == 0:
        counter += 1
        stamp[key][0] = counter
    elif stamp[key][1] != 0:
        return

    for e in GRAPH[key]:
        try:
            if stamp[e][0] == 0:
                dfs(e, GRAPH)
        except:
            pass
    counter += 1
    stamp[key][1] = counter
    return dfs global stamp, counter if stamp[key][0] == 0:
        counter += 1
        stamp[key][0] = counter
    elif stamp[key][1] != 0:
        return

     stamp[key][0] == 0 stamp[key][0] [key] stamp key 0 0 counter += 1 counter 1 stamp[key][0] = counter stamp[key][0] [key] stamp key 0 counter elif stamp[key][1] != 0:
        return

     stamp[key][1] != 0 stamp[key][1] [key] stamp key 1 0 return for e in GRAPH[key]:
        try:
            if stamp[e][0] == 0:
                dfs(e, GRAPH)
        except:
            pass
     e GRAPH[key] GRAPH key try:
            if stamp[e][0] == 0:
                dfs(e, GRAPH)
        except:
            pass
     except:
            pass
     if stamp[e][0] == 0:
                dfs(e, GRAPH)
         stamp[e][0] == 0 stamp[e][0] [e] stamp e 0 0 dfs(e, GRAPH) dfs e GRAPH counter += 1 counter 1 stamp[key][1] = counter stamp[key][1] [key] stamp key 1 counter return key key GRAPH GRAPH n = int(raw_input()) n int(raw_input()) int raw_input() raw_input x = {} x {} for i in range(n):
    seq = map(int, raw_input().split())
    key = seq[0]
    if key != 0:
        x[key] = seq[2:]
    else:
        x[key] = []  
    stamp[key] = [0, 0] i range(n) range n seq = map(int, raw_input().split()) seq map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split key = seq[0] key seq[0] seq 0 if key != 0:
        x[key] = seq[2:]
    else:
        x[key] = []  
     key != 0 key 0 x[key] = seq[2:] x[key] x key seq[2:] seq 2: 2 x[key] = [] x[key] x key [] stamp[key] = [0, 0] stamp[key] stamp key [0, 0] 0 0 for e in x.keys():
    dfs(e, x) e x.keys() x.keys x keys dfs(e, x) dfs e x for e in x.keys():
    print e, stamp[e][0], stamp[e][1] e x.keys() x.keys x keys print e stamp[e][0] [e] stamp e 0 stamp[e][1] [e] stamp e 1 def dfs(key, GRAPH):
    global stamp, counter
    if stamp[key][0] == 0:
        counter += 1
        stamp[key][0] = counter
    elif stamp[key][1] != 0:
        return

    for e in GRAPH[key]:
        try:
            if stamp[e][0] == 0:
                dfs(e, GRAPH)
        except:
            pass
    counter += 1
    stamp[key][1] = counter
    return def dfs(key, GRAPH):
    global stamp, counter
    if stamp[key][0] == 0:
        counter += 1
        stamp[key][0] = counter
    elif stamp[key][1] != 0:
        return

    for e in GRAPH[key]:
        try:
            if stamp[e][0] == 0:
                dfs(e, GRAPH)
        except:
            pass
    counter += 1
    stamp[key][1] = counter
    return dfs counter = 0 0 counter n = int(raw_input()) int(raw_input()) n key = seq[0] seq[0] key stamp = {} {} stamp x = {} {} x global stamp, counter seq = map(int, raw_input().split()) map(int, raw_input().split()) seq
import sys

global stamp, counter
stamp = {}
counter = 0

def dfs(key, GRAPH):
    global stamp, counter
    if stamp[key][0] == 0:
        counter += 1
        stamp[key][0] = counter
    elif stamp[key][1] != 0:
        return

    for e in GRAPH[key]:
        try:
            if stamp[e][0] == 0:
                dfs(e, GRAPH)
        except:
            pass
    counter += 1
    stamp[key][1] = counter
    return

n = int(raw_input())
x = {}
for i in range(n):
    seq = map(int, raw_input().split())
    key = seq[0]
    if key != 0:
        x[key] = seq[2:]
    else:
        x[key] = []  
    stamp[key] = [0, 0]

for e in x.keys():
    dfs(e, x)

for e in x.keys():
    print e, stamp[e][0], stamp[e][1]