class Node
  attr_reader :val, :child
  attr_accessor :d, :f
  def initialize(i, child)
    @val = i
    @child = child
    @d = nil
    @f = nil
  end
end

class Graph
  attr_accessor :node
  def initialize(n)
    @node = Array.new(n)
  end
  def depth_first_search(i, t)
    return t if @node[i].d
    @node[i].d = t
    t += 1
    @node[i].child.each{|ch|
      t = depth_first_search(ch-1, t)
    }
    @node[i].f = t
    return t + 1
  end
  def print
    @node.size.times{|i|
      puts "#{@node[i].val} #{@node[i].d} #{@node[i].f}"
    }
  end
end

n = gets.to_i
graph = Graph.new(n)
n.times{
  i, *child = gets.split.map(&:to_i)
  child.shift
  graph.node[i-1] = Node.new(i, child)
}
t = 1
0.upto(n-1){|i|
  t = graph.depth_first_search(i, t)
}
graph.print