# 隣接リスト
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)
check = [0]*n
count = 0
go = [0]*n
back = [0]*n

def dfs(v):
    #print(v)
    global count
    if check[v] == 0:
        check[v] = 1
        count += 1
        go[v] = count
        tolist = graph[v]
        if len(tolist) > 0:
            for i in tolist:
                dfs(i-1)
        count += 1
        back[v] = count

while True:
    if 0 in check:
        k = check.index(0)
        dfs(k)
    else:
        break

#print("check\t:{}".format(check))
#print("go\t:{}".format(go))
#print("back\t:{}".format(back))

for i in range(n):
    print("{} {} {}".format(i+1, go[i], back[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 check = [0]*n check [0]*n [0] 0 n count = 0 count 0 go = [0]*n go [0]*n [0] 0 n back = [0]*n back [0]*n [0] 0 n def dfs(v):
    #print(v)
    global count
    if check[v] == 0:
        check[v] = 1
        count += 1
        go[v] = count
        tolist = graph[v]
        if len(tolist) > 0:
            for i in tolist:
                dfs(i-1)
        count += 1
        back[v] = count dfs global count if check[v] == 0:
        check[v] = 1
        count += 1
        go[v] = count
        tolist = graph[v]
        if len(tolist) > 0:
            for i in tolist:
                dfs(i-1)
        count += 1
        back[v] = count check[v] == 0 check[v] check v 0 check[v] = 1 check[v] check v 1 count += 1 count 1 go[v] = count go[v] go v count tolist = graph[v] tolist graph[v] graph v if len(tolist) > 0:
            for i in tolist:
                dfs(i-1)
         len(tolist) > 0 len(tolist) len tolist 0 for i in tolist:
                dfs(i-1)
         i tolist dfs(i-1) dfs i-1 i 1 count += 1 count 1 back[v] = count back[v] back v count v v while True:
    if 0 in check:
        k = check.index(0)
        dfs(k)
    else:
        break

#print("check\t:{}".format(check))
#print("go\t:{}".format(go))
#print("back\t:{}".format(back)) True if 0 in check:
        k = check.index(0)
        dfs(k)
    else:
        break

#print("check\t:{}".format(check))
#print("go\t:{}".format(go))
#print("back\t:{}".format(back)) 0 in check 0 check k = check.index(0) k check.index(0) check.index check index 0 dfs(k) dfs k break for i in range(n):
    print("{} {} {}".format(i+1, go[i], back[i])) i range(n) range n print("{} {} {}".format(i+1, go[i], back[i])) print "{} {} {}".format(i+1, go[i], back[i]) "{} {} {}".format "{} {} {}" format i+1 i 1 go[i] go i back[i] back i back = [0]*n [0]*n back k = check.index(0) check.index(0) k graph = [] [] graph check = [0]*n [0]*n check def dfs(v):
    #print(v)
    global count
    if check[v] == 0:
        check[v] = 1
        count += 1
        go[v] = count
        tolist = graph[v]
        if len(tolist) > 0:
            for i in tolist:
                dfs(i-1)
        count += 1
        back[v] = count def dfs(v):
    #print(v)
    global count
    if check[v] == 0:
        check[v] = 1
        count += 1
        go[v] = count
        tolist = graph[v]
        if len(tolist) > 0:
            for i in tolist:
                dfs(i-1)
        count += 1
        back[v] = count dfs tmp = list(map(int, input().split())) list(map(int, input().split())) tmp go = [0]*n [0]*n go n = int(input()) int(input()) n count = 0 0 count
# 隣接リスト
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)
check = [0]*n
count = 0
go = [0]*n
back = [0]*n

def dfs(v):
    #print(v)
    global count
    if check[v] == 0:
        check[v] = 1
        count += 1
        go[v] = count
        tolist = graph[v]
        if len(tolist) > 0:
            for i in tolist:
                dfs(i-1)
        count += 1
        back[v] = count

while True:
    if 0 in check:
        k = check.index(0)
        dfs(k)
    else:
        break

#print("check\t:{}".format(check))
#print("go\t:{}".format(go))
#print("back\t:{}".format(back))

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

