
WHITE = 0
GRAY = 1
BLACK = 2

NIL = -1


def dfs(u):
    global time
    color[i] = GRAY
    time += 1
    d[u] = time
    for v in range(n):
        if m[u][v] and (color[v] == WHITE):
            dfs(v)
        color[u] = BLACK
    time += 1
    f[u] = time


def next(u):
    for v in range(nt[u], n + 1):
        nt[u] = v + 1
        if m[u][v]:
            return v
    return NIL
            


n = int(input())

m = [[0 for i in range(n + 1)] for j in range(n + 1)]
vid = [0] * n
d = [0] * n
f = [0] * n
S = []
color = [WHITE] * n
time = 0
nt = [0] * n

tmp = []
for i in range(n):
    nums=list(map(int,input().split()))
    tmp.append(nums)
    vid[i] = nums[0]

for i in range(n):
    for j in range(tmp[i][1]):
        m[i][vid.index(tmp[i][j + 2])] = 1

for i in range(n):
    if color[i] == WHITE:
        dfs(i)

for i in range(n):
    print(vid[i], d[i], f[i])



 WHITE = 0 WHITE 0 GRAY = 1 GRAY 1 BLACK = 2 BLACK 2 NIL = -1 NIL -1 def dfs(u):
    global time
    color[i] = GRAY
    time += 1
    d[u] = time
    for v in range(n):
        if m[u][v] and (color[v] == WHITE):
            dfs(v)
        color[u] = BLACK
    time += 1
    f[u] = time dfs global time color[i] = GRAY color[i] color i GRAY time += 1 time 1 d[u] = time d[u] d u time for v in range(n):
        if m[u][v] and (color[v] == WHITE):
            dfs(v)
        color[u] = BLACK
     v range(n) range n if m[u][v] and (color[v] == WHITE):
            dfs(v)
         m[u][v] and (color[v] == WHITE) m[u][v] [u] m u v color[v] == WHITE color[v] color v WHITE dfs(v) dfs v color[u] = BLACK color[u] color u BLACK time += 1 time 1 f[u] = time f[u] f u time u u def next(u):
    for v in range(nt[u], n + 1):
        nt[u] = v + 1
        if m[u][v]:
            return v
    return NIL
             next for v in range(nt[u], n + 1):
        nt[u] = v + 1
        if m[u][v]:
            return v
     v range(nt[u], n + 1) range nt[u] nt u n + 1 n 1 nt[u] = v + 1 nt[u] nt u v + 1 v 1 if m[u][v]:
            return v
     m[u][v] [u] m u v return v v return NIL NIL u u n = int(input()) n int(input()) int input() input [0 for i in range(n + 1)] for j in range(n + 1) for j in range(n + 1) j range(n + 1) range n + 1 n 1 for j in range(n + 1) [0 for i in range(n + 1)] m = [[0 for i in range(n + 1)] for j in range(n + 1)] m [[0 for i in range(n + 1)] for j in range(n + 1)] vid = [0] * n vid [0] * n [0] 0 n d = [0] * n d [0] * n [0] 0 n f = [0] * n f [0] * n [0] 0 n S = [] S [] color = [WHITE] * n color [WHITE] * n [WHITE] WHITE n time = 0 time 0 nt = [0] * n nt [0] * n [0] 0 n tmp = [] tmp [] for i in range(n):
    nums=list(map(int,input().split()))
    tmp.append(nums)
    vid[i] = nums[0] i range(n) range n nums=list(map(int,input().split())) nums list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split tmp.append(nums) tmp.append tmp append nums vid[i] = nums[0] vid[i] vid i nums[0] nums 0 for i in range(n):
    for j in range(tmp[i][1]):
        m[i][vid.index(tmp[i][j + 2])] = 1 i range(n) range n for j in range(tmp[i][1]):
        m[i][vid.index(tmp[i][j + 2])] = 1 j range(tmp[i][1]) range tmp[i][1] [i] tmp i 1 m[i][vid.index(tmp[i][j + 2])] = 1 m[i][vid.index(tmp[i][j + 2])] [i] m i vid.index(tmp[i][j + 2]) vid.index vid index tmp[i][j + 2] [i] tmp i j + 2 j 2 1 for i in range(n):
    if color[i] == WHITE:
        dfs(i) i range(n) range n if color[i] == WHITE:
        dfs(i) color[i] == WHITE color[i] color i WHITE dfs(i) dfs i for i in range(n):
    print(vid[i], d[i], f[i]) i range(n) range n print(vid[i], d[i], f[i]) print vid[i] vid i d[i] d i f[i] f i m = [[0 for i in range(n + 1)] for j in range(n + 1)] [[0 for i in range(n + 1)] for j in range(n + 1)] m WHITE = 0 0 WHITE GRAY = 1 1 GRAY color = [WHITE] * n [WHITE] * n color S = [] [] S time = 0 0 time def dfs(u):
    global time
    color[i] = GRAY
    time += 1
    d[u] = time
    for v in range(n):
        if m[u][v] and (color[v] == WHITE):
            dfs(v)
        color[u] = BLACK
    time += 1
    f[u] = time def dfs(u):
    global time
    color[i] = GRAY
    time += 1
    d[u] = time
    for v in range(n):
        if m[u][v] and (color[v] == WHITE):
            dfs(v)
        color[u] = BLACK
    time += 1
    f[u] = time dfs nums=list(map(int,input().split())) list(map(int,input().split())) nums f = [0] * n [0] * n f nt = [0] * n [0] * n nt BLACK = 2 2 BLACK vid = [0] * n [0] * n vid n = int(input()) int(input()) n d = [0] * n [0] * n d NIL = -1 -1 NIL def next(u):
    for v in range(nt[u], n + 1):
        nt[u] = v + 1
        if m[u][v]:
            return v
    return NIL
             def next(u):
    for v in range(nt[u], n + 1):
        nt[u] = v + 1
        if m[u][v]:
            return v
    return NIL
             next tmp = [] [] tmp

WHITE = 0
GRAY = 1
BLACK = 2

NIL = -1


def dfs(u):
    global time
    color[i] = GRAY
    time += 1
    d[u] = time
    for v in range(n):
        if m[u][v] and (color[v] == WHITE):
            dfs(v)
        color[u] = BLACK
    time += 1
    f[u] = time


def next(u):
    for v in range(nt[u], n + 1):
        nt[u] = v + 1
        if m[u][v]:
            return v
    return NIL
            


n = int(input())

m = [[0 for i in range(n + 1)] for j in range(n + 1)]
vid = [0] * n
d = [0] * n
f = [0] * n
S = []
color = [WHITE] * n
time = 0
nt = [0] * n

tmp = []
for i in range(n):
    nums=list(map(int,input().split()))
    tmp.append(nums)
    vid[i] = nums[0]

for i in range(n):
    for j in range(tmp[i][1]):
        m[i][vid.index(tmp[i][j + 2])] = 1

for i in range(n):
    if color[i] == WHITE:
        dfs(i)

for i in range(n):
    print(vid[i], d[i], f[i])




