n = int(raw_input())
N = 100
WHITE = 0
GRAY = 1
BLACK = 2
Color = [WHITE for i in range(n)]
#M = [[0 for i in range(N)] for j in range(N)]
tt = 0
d = [0 for i in range(n)]
f = [0 for i in range(n)]
def dfs_visit(u):
    Color[u] = GRAY
    global tt
    tt += 1
    d[u] = tt
    for v in range(n):
        if M[u][v] == 0:
            continue
        if Color[v] == WHITE:
            dfs_visit(v)
    Color[u] = BLACK 
    tt += 1
    f[u] = tt
 
def dfs():
    #Color = [WHITE for i in range(n)]
    tt = 0
     
    for u in range(n):
        if Color[u] == WHITE:
            dfs_visit(u)
    for u in range(n):
        print "%d %d %d" %(u + 1, d[u], f[u])
 
M = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
    tmp = map(int, raw_input().split())
    u = tmp[0]
    k = tmp[1]
    u -= 1
    for j in range(k):
        v = tmp[j + 2]
        v -= 1
        M[u][v] = 1
dfs() n = int(raw_input()) n int(raw_input()) int raw_input() raw_input N = 100 N 100 WHITE = 0 WHITE 0 GRAY = 1 GRAY 1 BLACK = 2 BLACK 2 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)] tt = 0 tt 0 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)] def dfs_visit(u):
    Color[u] = GRAY
    global tt
    tt += 1
    d[u] = tt
    for v in range(n):
        if M[u][v] == 0:
            continue
        if Color[v] == WHITE:
            dfs_visit(v)
    Color[u] = BLACK 
    tt += 1
    f[u] = tt
  dfs_visit Color[u] = GRAY Color[u] Color u GRAY global tt tt += 1 tt 1 d[u] = tt d[u] d u tt for v in range(n):
        if M[u][v] == 0:
            continue
        if Color[v] == WHITE:
            dfs_visit(v)
     v range(n) range n if M[u][v] == 0:
            continue
         M[u][v] == 0 M[u][v] [u] M u v 0 continue if Color[v] == WHITE:
            dfs_visit(v)
     Color[v] == WHITE Color[v] Color v WHITE dfs_visit(v) dfs_visit v Color[u] = BLACK Color[u] Color u BLACK tt += 1 tt 1 f[u] = tt f[u] f u tt u u def dfs():
    #Color = [WHITE for i in range(n)]
    tt = 0
     
    for u in range(n):
        if Color[u] == WHITE:
            dfs_visit(u)
    for u in range(n):
        print "%d %d %d" %(u + 1, d[u], f[u])
  dfs tt = 0 tt 0 for u in range(n):
        if Color[u] == WHITE:
            dfs_visit(u)
     u range(n) range n if Color[u] == WHITE:
            dfs_visit(u)
     Color[u] == WHITE Color[u] Color u WHITE dfs_visit(u) dfs_visit u for u in range(n):
        print "%d %d %d" %(u + 1, d[u], f[u])
  u range(n) range n print "%d %d %d" %(u + 1, d[u], f[u]) "%d %d %d" (u + 1, d[u], f[u]) u + 1 u 1 d[u] d u f[u] f u [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)] M = [[0 for j in range(n)] for i in range(n)] M [[0 for j in range(n)] for i in range(n)] for i in range(n):
    tmp = map(int, raw_input().split())
    u = tmp[0]
    k = tmp[1]
    u -= 1
    for j in range(k):
        v = tmp[j + 2]
        v -= 1
        M[u][v] = 1 i range(n) range n tmp = map(int, raw_input().split()) tmp map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split u = tmp[0] u tmp[0] tmp 0 k = tmp[1] k tmp[1] tmp 1 u -= 1 u 1 for j in range(k):
        v = tmp[j + 2]
        v -= 1
        M[u][v] = 1 j range(k) range k v = tmp[j + 2] v tmp[j + 2] tmp j + 2 j 2 v -= 1 v 1 M[u][v] = 1 M[u][v] [u] M u v 1 dfs() dfs u = tmp[0] tmp[0] u d = [0 for i in range(n)] [0 for i in range(n)] d k = tmp[1] tmp[1] k f = [0 for i in range(n)] [0 for i in range(n)] f v = tmp[j + 2] tmp[j + 2] v tt = 0 0 tt def dfs_visit(u):
    Color[u] = GRAY
    global tt
    tt += 1
    d[u] = tt
    for v in range(n):
        if M[u][v] == 0:
            continue
        if Color[v] == WHITE:
            dfs_visit(v)
    Color[u] = BLACK 
    tt += 1
    f[u] = tt
  def dfs_visit(u):
    Color[u] = GRAY
    global tt
    tt += 1
    d[u] = tt
    for v in range(n):
        if M[u][v] == 0:
            continue
        if Color[v] == WHITE:
            dfs_visit(v)
    Color[u] = BLACK 
    tt += 1
    f[u] = tt
  dfs_visit n = int(raw_input()) int(raw_input()) n u -= 1 1 u N = 100 100 N v -= 1 1 v BLACK = 2 2 BLACK GRAY = 1 1 GRAY tmp = map(int, raw_input().split()) map(int, raw_input().split()) tmp WHITE = 0 0 WHITE def dfs():
    #Color = [WHITE for i in range(n)]
    tt = 0
     
    for u in range(n):
        if Color[u] == WHITE:
            dfs_visit(u)
    for u in range(n):
        print "%d %d %d" %(u + 1, d[u], f[u])
  def dfs():
    #Color = [WHITE for i in range(n)]
    tt = 0
     
    for u in range(n):
        if Color[u] == WHITE:
            dfs_visit(u)
    for u in range(n):
        print "%d %d %d" %(u + 1, d[u], f[u])
  dfs Color = [WHITE for i in range(n)] [WHITE for i in range(n)] Color M = [[0 for j in range(n)] for i in range(n)] [[0 for j in range(n)] for i in range(n)] M
n = int(raw_input())
N = 100
WHITE = 0
GRAY = 1
BLACK = 2
Color = [WHITE for i in range(n)]
#M = [[0 for i in range(N)] for j in range(N)]
tt = 0
d = [0 for i in range(n)]
f = [0 for i in range(n)]
def dfs_visit(u):
    Color[u] = GRAY
    global tt
    tt += 1
    d[u] = tt
    for v in range(n):
        if M[u][v] == 0:
            continue
        if Color[v] == WHITE:
            dfs_visit(v)
    Color[u] = BLACK 
    tt += 1
    f[u] = tt
 
def dfs():
    #Color = [WHITE for i in range(n)]
    tt = 0
     
    for u in range(n):
        if Color[u] == WHITE:
            dfs_visit(u)
    for u in range(n):
        print "%d %d %d" %(u + 1, d[u], f[u])
 
M = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
    tmp = map(int, raw_input().split())
    u = tmp[0]
    k = tmp[1]
    u -= 1
    for j in range(k):
        v = tmp[j + 2]
        v -= 1
        M[u][v] = 1
dfs()