n = int(input())

graph = []
for _ in range(n):
    tmp = list(map(int, input().split()))
    if tmp[1] == 0:
        graph.append([])
    else:
        graph.append(tmp[2:])
#print(graph)

seen = [0]*n
to_do = []
in_list = [0]*n
out_list = [0]*n
count = 0

def dfs(v):
    #print(v)
    global count
    if seen[v] == 0:
        seen[v] = 1
        count += 1
        in_list[v] = count
        to_do = graph[v]
        #print(in_list)
        #print(to_do)
        if len(to_do) > 0:
            for i in to_do:
                dfs(i-1)
        count += 1
        out_list[v] = count
        #print(out_list)
while True:
    if 0 in seen:
        k = seen.index(0)
        dfs(k)
    else:
        break

for i in range(n):
    print("{} {} {}".format(i+1,in_list[i],out_list[i])) n = int(input()) n int(input()) int input() input graph = [] graph [] for _ in range(n):
    tmp = list(map(int, input().split()))
    if tmp[1] == 0:
        graph.append([])
    else:
        graph.append(tmp[2:])
#print(graph) _ range(n) range n tmp = list(map(int, input().split())) tmp list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split if tmp[1] == 0:
        graph.append([])
    else:
        graph.append(tmp[2:])
#print(graph) tmp[1] == 0 tmp[1] tmp 1 0 graph.append([]) graph.append graph append [] graph.append(tmp[2:]) graph.append graph append tmp[2:] tmp 2: 2 seen = [0]*n seen [0]*n [0] 0 n to_do = [] to_do [] in_list = [0]*n in_list [0]*n [0] 0 n out_list = [0]*n out_list [0]*n [0] 0 n count = 0 count 0 def dfs(v):
    #print(v)
    global count
    if seen[v] == 0:
        seen[v] = 1
        count += 1
        in_list[v] = count
        to_do = graph[v]
        #print(in_list)
        #print(to_do)
        if len(to_do) > 0:
            for i in to_do:
                dfs(i-1)
        count += 1
        out_list[v] = count
        #print(out_list) dfs global count if seen[v] == 0:
        seen[v] = 1
        count += 1
        in_list[v] = count
        to_do = graph[v]
        #print(in_list)
        #print(to_do)
        if len(to_do) > 0:
            for i in to_do:
                dfs(i-1)
        count += 1
        out_list[v] = count
        #print(out_list) seen[v] == 0 seen[v] seen v 0 seen[v] = 1 seen[v] seen v 1 count += 1 count 1 in_list[v] = count in_list[v] in_list v count to_do = graph[v] to_do graph[v] graph v if len(to_do) > 0:
            for i in to_do:
                dfs(i-1)
         len(to_do) > 0 len(to_do) len to_do 0 for i in to_do:
                dfs(i-1)
         i to_do dfs(i-1) dfs i-1 i 1 count += 1 count 1 out_list[v] = count out_list[v] out_list v count v v while True:
    if 0 in seen:
        k = seen.index(0)
        dfs(k)
    else:
        break True if 0 in seen:
        k = seen.index(0)
        dfs(k)
    else:
        break 0 in seen 0 seen k = seen.index(0) k seen.index(0) seen.index seen index 0 dfs(k) dfs k break for i in range(n):
    print("{} {} {}".format(i+1,in_list[i],out_list[i])) i range(n) range n print("{} {} {}".format(i+1,in_list[i],out_list[i])) print "{} {} {}".format(i+1,in_list[i],out_list[i]) "{} {} {}".format "{} {} {}" format i+1 i 1 in_list[i] in_list i out_list[i] out_list i seen = [0]*n [0]*n seen graph = [] [] graph out_list = [0]*n [0]*n out_list k = seen.index(0) seen.index(0) k to_do = [] [] to_do n = int(input()) int(input()) n tmp = list(map(int, input().split())) list(map(int, input().split())) tmp in_list = [0]*n [0]*n in_list count = 0 0 count def dfs(v):
    #print(v)
    global count
    if seen[v] == 0:
        seen[v] = 1
        count += 1
        in_list[v] = count
        to_do = graph[v]
        #print(in_list)
        #print(to_do)
        if len(to_do) > 0:
            for i in to_do:
                dfs(i-1)
        count += 1
        out_list[v] = count
        #print(out_list) def dfs(v):
    #print(v)
    global count
    if seen[v] == 0:
        seen[v] = 1
        count += 1
        in_list[v] = count
        to_do = graph[v]
        #print(in_list)
        #print(to_do)
        if len(to_do) > 0:
            for i in to_do:
                dfs(i-1)
        count += 1
        out_list[v] = count
        #print(out_list) dfs
n = int(input())

graph = []
for _ in range(n):
    tmp = list(map(int, input().split()))
    if tmp[1] == 0:
        graph.append([])
    else:
        graph.append(tmp[2:])
#print(graph)

seen = [0]*n
to_do = []
in_list = [0]*n
out_list = [0]*n
count = 0

def dfs(v):
    #print(v)
    global count
    if seen[v] == 0:
        seen[v] = 1
        count += 1
        in_list[v] = count
        to_do = graph[v]
        #print(in_list)
        #print(to_do)
        if len(to_do) > 0:
            for i in to_do:
                dfs(i-1)
        count += 1
        out_list[v] = count
        #print(out_list)
while True:
    if 0 in seen:
        k = seen.index(0)
        dfs(k)
    else:
        break

for i in range(n):
    print("{} {} {}".format(i+1,in_list[i],out_list[i]))
