# -*- coding: utf-8 -*-
"""
Created on Thu May  7 23:19:34 2020

@author: Kanaru Sato
"""
def dfs(v):
    global t
    d[v] = t
    t += 1
    if conlist[v]:
        for connectedv in conlist[v]:
            if d[connectedv] == -1:
                dfs(connectedv)
    f[v] = t
    t += 1

n = int(input())
conlist = [[] for i in range(n)]
for i in range(n):
    _ = list(map(int,input().split()))
    [conlist[i].append(_[k]-1) for k in range(2,_[1]+2)]

d = [-1 for i in range(n)]
f = [-1 for i in range(n)]
t = 1

for i in range(n):
    if d[i] == -1:
        dfs(i)    

for i in range(n):
    print(i+1,d[i],f[i]) """
Created on Thu May  7 23:19:34 2020

@author: Kanaru Sato
""" def dfs(v):
    global t
    d[v] = t
    t += 1
    if conlist[v]:
        for connectedv in conlist[v]:
            if d[connectedv] == -1:
                dfs(connectedv)
    f[v] = t
    t += 1 dfs global t d[v] = t d[v] d v t t += 1 t 1 if conlist[v]:
        for connectedv in conlist[v]:
            if d[connectedv] == -1:
                dfs(connectedv)
     conlist[v] conlist v for connectedv in conlist[v]:
            if d[connectedv] == -1:
                dfs(connectedv)
     connectedv conlist[v] conlist v if d[connectedv] == -1:
                dfs(connectedv)
     d[connectedv] == -1 d[connectedv] d connectedv -1 dfs(connectedv) dfs connectedv f[v] = t f[v] f v t t += 1 t 1 v v n = int(input()) n int(input()) int input() input [] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [] conlist = [[] for i in range(n)] conlist [[] for i in range(n)] for i in range(n):
    _ = list(map(int,input().split()))
    [conlist[i].append(_[k]-1) for k in range(2,_[1]+2)] i range(n) range n _ = list(map(int,input().split())) _ list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split conlist[i].append(_[k]-1) for k in range(2,_[1]+2) for k in range(2,_[1]+2) k range(2,_[1]+2) range 2 _[1]+2 _[1] _ 1 2 for k in range(2,_[1]+2) conlist[i].append(_[k]-1) [i].append [i] conlist i append _[k]-1 _[k] _ k 1 [conlist[i].append(_[k]-1) for k in range(2,_[1]+2)] -1 for i in range(n) for i in range(n) i range(n) range n for i in range(n) -1 d = [-1 for i in range(n)] d [-1 for i in range(n)] -1 for i in range(n) for i in range(n) i range(n) range n for i in range(n) -1 f = [-1 for i in range(n)] f [-1 for i in range(n)] t = 1 t 1 for i in range(n):
    if d[i] == -1:
        dfs(i)     i range(n) range n if d[i] == -1:
        dfs(i)     d[i] == -1 d[i] d i -1 dfs(i) dfs i 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 conlist = [[] for i in range(n)] [[] for i in range(n)] conlist def dfs(v):
    global t
    d[v] = t
    t += 1
    if conlist[v]:
        for connectedv in conlist[v]:
            if d[connectedv] == -1:
                dfs(connectedv)
    f[v] = t
    t += 1 def dfs(v):
    global t
    d[v] = t
    t += 1
    if conlist[v]:
        for connectedv in conlist[v]:
            if d[connectedv] == -1:
                dfs(connectedv)
    f[v] = t
    t += 1 dfs n = int(input()) int(input()) n _ = list(map(int,input().split())) list(map(int,input().split())) _ f = [-1 for i in range(n)] [-1 for i in range(n)] f d = [-1 for i in range(n)] [-1 for i in range(n)] d t = 1 1 t
# -*- coding: utf-8 -*-
"""
Created on Thu May  7 23:19:34 2020

@author: Kanaru Sato
"""
def dfs(v):
    global t
    d[v] = t
    t += 1
    if conlist[v]:
        for connectedv in conlist[v]:
            if d[connectedv] == -1:
                dfs(connectedv)
    f[v] = t
    t += 1

n = int(input())
conlist = [[] for i in range(n)]
for i in range(n):
    _ = list(map(int,input().split()))
    [conlist[i].append(_[k]-1) for k in range(2,_[1]+2)]

d = [-1 for i in range(n)]
f = [-1 for i in range(n)]
t = 1

for i in range(n):
    if d[i] == -1:
        dfs(i)    

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