from enum import Enum, auto

class Color(Enum):
    WHITE = auto() # 未訪問の頂点
    GRAY = auto() # 訪問済みだが, 全ての接点の調査は済んでいない状態の接点
    BLACK = auto() # 訪問, 調査済みの接点

n = int(input())
d = [0 for i in range(n)]
f = [0 for i in range(n)]

colors = [] # 頂点の訪問状態
A = [[0 for j in range(n)] for i in range(n)] # 隣接行列
# stack = [] ## スタックによる実装では頂点の保持が必要 => 再帰によって実装

# 隣接行列の初期化
for i in range(n):
    arr = list(map(int, input().split(' ')))
    u, k, v = arr[0], arr[1], arr[2:]
    for j in range(k):
        A[u-1][v[j]-1] = 1

time = 0
def dfs_init():
    global colors
    colors = [Color.WHITE for i in range(n)]
    dfs(0)

def dfs(u):
    global time
    colors[u] = Color.GRAY
    time += 1
    d[u] = time
    for v in range(n):
        if A[u][v] == 1 and colors[v] == Color.WHITE:
            dfs(v)
    colors[u] = Color.BLACK
    time += 1
    f[u] = time

dfs_init()
for u in range(n):
    if colors[u] == Color.WHITE:
        dfs(u)

# 出力
for i in range(n):
    print(i+1, d[i], f[i])
 from enum import Enum, auto class Color(Enum):
    WHITE = auto() # 未訪問の頂点
    GRAY = auto() # 訪問済みだが, 全ての接点の調査は済んでいない状態の接点
    BLACK = auto() # 訪問, 調査済みの接点 Color WHITE = auto() WHITE auto() auto GRAY = auto() GRAY auto() auto BLACK = auto() BLACK auto() auto Enum n = int(input()) n int(input()) int input() input 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 d = [0 for i in range(n)] d [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 f = [0 for i in range(n)] f [0 for i in range(n)] colors = [] colors [] [0 for j in range(n)] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [0 for j in range(n)] A = [[0 for j in range(n)] for i in range(n)] A [[0 for j in range(n)] for i in range(n)] for i in range(n):
    arr = list(map(int, input().split(' ')))
    u, k, v = arr[0], arr[1], arr[2:]
    for j in range(k):
        A[u-1][v[j]-1] = 1 i range(n) range n arr = list(map(int, input().split(' '))) arr list(map(int, input().split(' '))) list map(int, input().split(' ')) map int input().split(' ') ().split () input split ' ' u, k, v = arr[0], arr[1], arr[2:] u arr[0] arr 0 k arr[1] arr 1 v arr[2:] arr 2: 2 for j in range(k):
        A[u-1][v[j]-1] = 1 j range(k) range k A[u-1][v[j]-1] = 1 A[u-1][v[j]-1] [u-1] A u-1 u 1 v[j]-1 v[j] v j 1 1 time = 0 time 0 def dfs_init():
    global colors
    colors = [Color.WHITE for i in range(n)]
    dfs(0) dfs_init global colors Color.WHITE for i in range(n) for i in range(n) i range(n) range n for i in range(n) Color.WHITE Color WHITE colors = [Color.WHITE for i in range(n)] colors [Color.WHITE for i in range(n)] dfs(0) dfs 0 def dfs(u):
    global time
    colors[u] = Color.GRAY
    time += 1
    d[u] = time
    for v in range(n):
        if A[u][v] == 1 and colors[v] == Color.WHITE:
            dfs(v)
    colors[u] = Color.BLACK
    time += 1
    f[u] = time dfs global time colors[u] = Color.GRAY colors[u] colors u Color.GRAY Color GRAY time += 1 time 1 d[u] = time d[u] d u time for v in range(n):
        if A[u][v] == 1 and colors[v] == Color.WHITE:
            dfs(v)
     v range(n) range n if A[u][v] == 1 and colors[v] == Color.WHITE:
            dfs(v)
     A[u][v] == 1 and colors[v] == Color.WHITE A[u][v] == 1 A[u][v] [u] A u v 1 colors[v] == Color.WHITE colors[v] colors v Color.WHITE Color WHITE dfs(v) dfs v colors[u] = Color.BLACK colors[u] colors u Color.BLACK Color BLACK time += 1 time 1 f[u] = time f[u] f u time u u dfs_init() dfs_init for u in range(n):
    if colors[u] == Color.WHITE:
        dfs(u)

# 出力 u range(n) range n if colors[u] == Color.WHITE:
        dfs(u)

# 出力 colors[u] == Color.WHITE colors[u] colors u Color.WHITE Color WHITE dfs(u) dfs u for i in range(n):
    print(i+1, d[i], f[i]) i range(n) range n print(i+1, d[i], f[i]) print i+1 i 1 d[i] d i f[i] f i n = int(input()) int(input()) n f = [0 for i in range(n)] [0 for i in range(n)] f k, v = arr[0], arr[1], arr[2:] arr[1] k time = 0 0 time colors = [] [] colors d = [0 for i in range(n)] [0 for i in range(n)] d def dfs(u):
    global time
    colors[u] = Color.GRAY
    time += 1
    d[u] = time
    for v in range(n):
        if A[u][v] == 1 and colors[v] == Color.WHITE:
            dfs(v)
    colors[u] = Color.BLACK
    time += 1
    f[u] = time def dfs(u):
    global time
    colors[u] = Color.GRAY
    time += 1
    d[u] = time
    for v in range(n):
        if A[u][v] == 1 and colors[v] == Color.WHITE:
            dfs(v)
    colors[u] = Color.BLACK
    time += 1
    f[u] = time dfs def dfs_init():
    global colors
    colors = [Color.WHITE for i in range(n)]
    dfs(0) def dfs_init():
    global colors
    colors = [Color.WHITE for i in range(n)]
    dfs(0) dfs_init arr = list(map(int, input().split(' '))) list(map(int, input().split(' '))) arr v = arr[0], arr[1], arr[2:] arr[2:] v u, k, v = arr[0], arr[1], arr[2:] arr[0] u class Color(Enum):
    WHITE = auto() # 未訪問の頂点
    GRAY = auto() # 訪問済みだが, 全ての接点の調査は済んでいない状態の接点
    BLACK = auto() # 訪問, 調査済みの接点 class Color(Enum):
    WHITE = auto() # 未訪問の頂点
    GRAY = auto() # 訪問済みだが, 全ての接点の調査は済んでいない状態の接点
    BLACK = auto() # 訪問, 調査済みの接点 Color A = [[0 for j in range(n)] for i in range(n)] [[0 for j in range(n)] for i in range(n)] A
from enum import Enum, auto

class Color(Enum):
    WHITE = auto() # 未訪問の頂点
    GRAY = auto() # 訪問済みだが, 全ての接点の調査は済んでいない状態の接点
    BLACK = auto() # 訪問, 調査済みの接点

n = int(input())
d = [0 for i in range(n)]
f = [0 for i in range(n)]

colors = [] # 頂点の訪問状態
A = [[0 for j in range(n)] for i in range(n)] # 隣接行列
# stack = [] ## スタックによる実装では頂点の保持が必要 => 再帰によって実装

# 隣接行列の初期化
for i in range(n):
    arr = list(map(int, input().split(' ')))
    u, k, v = arr[0], arr[1], arr[2:]
    for j in range(k):
        A[u-1][v[j]-1] = 1

time = 0
def dfs_init():
    global colors
    colors = [Color.WHITE for i in range(n)]
    dfs(0)

def dfs(u):
    global time
    colors[u] = Color.GRAY
    time += 1
    d[u] = time
    for v in range(n):
        if A[u][v] == 1 and colors[v] == Color.WHITE:
            dfs(v)
    colors[u] = Color.BLACK
    time += 1
    f[u] = time

dfs_init()
for u in range(n):
    if colors[u] == Color.WHITE:
        dfs(u)

# 出力
for i in range(n):
    print(i+1, d[i], f[i])

