#coding: utf-8

n = int(input())
color = ["white" for i in range(n)]
d = [[] for i in range(n)]
global t
t = 0
M = [[False for i in range(n)] for j in range(n)]
for i in range(n):
    data = list(map(int,input().split()))
    u = data[0]
    k = data[1]
    if i == 0:
        start = u
    for v in data[2:2+k]:
        M[u-1][v-1] = True


def search(u,t):
    t += 1
    color[u-1] = "gray"
    d[u-1].append(t)
    for v in range(1,n+1):
        if M[u-1][v-1] and color[v-1] == "white":
            t = search(v,t)
    color[u-1] = "black"
    t += 1
    d[u-1].append(t)
    return t

t = search(start, t)
for i in range(1,n+1):
    if color[i-1] == "white":
        t = search(i, t)

for i in range(n):
    print(i+1, d[i][0], d[i][1])
 n = int(input()) n int(input()) int input() input "white" for i in range(n) for i in range(n) i range(n) range n for i in range(n) "white" color = ["white" for i in range(n)] color ["white" for i in range(n)] [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] d = [[] for i in range(n)] d [[] for i in range(n)] global t t = 0 t 0 [False for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [False for i in range(n)] M = [[False for i in range(n)] for j in range(n)] M [[False for i in range(n)] for j in range(n)] for i in range(n):
    data = list(map(int,input().split()))
    u = data[0]
    k = data[1]
    if i == 0:
        start = u
    for v in data[2:2+k]:
        M[u-1][v-1] = True i range(n) range n data = list(map(int,input().split())) data list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split u = data[0] u data[0] data 0 k = data[1] k data[1] data 1 if i == 0:
        start = u
     i == 0 i 0 start = u start u for v in data[2:2+k]:
        M[u-1][v-1] = True v data[2:2+k] data 2:2+k 2 2+k 2 k M[u-1][v-1] = True M[u-1][v-1] [u-1] M u-1 u 1 v-1 v 1 True def search(u,t):
    t += 1
    color[u-1] = "gray"
    d[u-1].append(t)
    for v in range(1,n+1):
        if M[u-1][v-1] and color[v-1] == "white":
            t = search(v,t)
    color[u-1] = "black"
    t += 1
    d[u-1].append(t)
    return t search t += 1 t 1 color[u-1] = "gray" color[u-1] color u-1 u 1 "gray" d[u-1].append(t) [u-1].append [u-1] d u-1 u 1 append t for v in range(1,n+1):
        if M[u-1][v-1] and color[v-1] == "white":
            t = search(v,t)
     v range(1,n+1) range 1 n+1 n 1 if M[u-1][v-1] and color[v-1] == "white":
            t = search(v,t)
     M[u-1][v-1] and color[v-1] == "white" M[u-1][v-1] [u-1] M u-1 u 1 v-1 v 1 color[v-1] == "white" color[v-1] color v-1 v 1 "white" t = search(v,t) t search(v,t) search v t color[u-1] = "black" color[u-1] color u-1 u 1 "black" t += 1 t 1 d[u-1].append(t) [u-1].append [u-1] d u-1 u 1 append t return t t u u t t t = search(start, t) t search(start, t) search start t for i in range(1,n+1):
    if color[i-1] == "white":
        t = search(i, t) i range(1,n+1) range 1 n+1 n 1 if color[i-1] == "white":
        t = search(i, t) color[i-1] == "white" color[i-1] color i-1 i 1 "white" t = search(i, t) t search(i, t) search i t for i in range(n):
    print(i+1, d[i][0], d[i][1]) i range(n) range n print(i+1, d[i][0], d[i][1]) print i+1 i 1 d[i][0] [i] d i 0 d[i][1] [i] d i 1 start = u u start n = int(input()) int(input()) n t = search(i, t) search(i, t) t global t d = [[] for i in range(n)] [[] for i in range(n)] d data = list(map(int,input().split())) list(map(int,input().split())) data u = data[0] data[0] u def search(u,t):
    t += 1
    color[u-1] = "gray"
    d[u-1].append(t)
    for v in range(1,n+1):
        if M[u-1][v-1] and color[v-1] == "white":
            t = search(v,t)
    color[u-1] = "black"
    t += 1
    d[u-1].append(t)
    return t def search(u,t):
    t += 1
    color[u-1] = "gray"
    d[u-1].append(t)
    for v in range(1,n+1):
        if M[u-1][v-1] and color[v-1] == "white":
            t = search(v,t)
    color[u-1] = "black"
    t += 1
    d[u-1].append(t)
    return t search color = ["white" for i in range(n)] ["white" for i in range(n)] color k = data[1] data[1] k t = 0 0 t M = [[False for i in range(n)] for j in range(n)] [[False for i in range(n)] for j in range(n)] M t = search(start, t) search(start, t) t
#coding: utf-8

n = int(input())
color = ["white" for i in range(n)]
d = [[] for i in range(n)]
global t
t = 0
M = [[False for i in range(n)] for j in range(n)]
for i in range(n):
    data = list(map(int,input().split()))
    u = data[0]
    k = data[1]
    if i == 0:
        start = u
    for v in data[2:2+k]:
        M[u-1][v-1] = True


def search(u,t):
    t += 1
    color[u-1] = "gray"
    d[u-1].append(t)
    for v in range(1,n+1):
        if M[u-1][v-1] and color[v-1] == "white":
            t = search(v,t)
    color[u-1] = "black"
    t += 1
    d[u-1].append(t)
    return t

t = search(start, t)
for i in range(1,n+1):
    if color[i-1] == "white":
        t = search(i, t)

for i in range(n):
    print(i+1, d[i][0], d[i][1])

