END { load __FILE__ unless $stdin.eof? }

class SCC
  def initialize(n = 0)
    @n = n
    @edges = []
  end

  def add_edge(from, to)
    @edges << [from, to]
    self
  end

  def scc
    group_num, ids = scc_ids
    groups = Array.new(group_num) { [] }
    ids.each_with_index { |id, i| groups[id] << i }
    groups
  end

  private

  def scc_ids
    g_start = Array.new(@n + 1, 0)
    g_elist = Array.new(@edges.size)
    @edges.each { |from, _| g_start[from+1] += 1 }
    1.upto(@n) { |i| g_start[i] += g_start[i-1] }
    g_start.dup.tap do |counter|
      @edges.each do |from, to|
        g_elist[counter[from]] = to
        counter[from] += 1
      end
    end

    now_ord = 0
    group_num = 0
    visited = []
    low = Array.new(@n)
    ord = Array.new(@n)
    ids = Array.new(@n)

    dfs = lambda do |this, v|
      low[v] = ord[v] = now_ord
      now_ord += 1
      visited << v

      (g_start[v]...g_start[v+1]).each do |i|
        to = g_elist[i]
        if ord[to]
          low[v] = [low[v], ord[to]].min
        else
          this.call(this, to)
          low[v] = [low[v], low[to]].min
        end
      end

      if low[v] == ord[v]
        begin
          u = visited.pop
          ord[u] = @n
          ids[u] = group_num
        end until u == v
        group_num += 1
      end
    end

    @n.times { |i| dfs.call(dfs, i) unless ord[i] }
    ids.map! { |x| group_num - 1 - x }

    [group_num, ids]
  end
end

n = gets.to_i
towns = Array.new(n) { |i| gets.split.map!(&:to_i) << i }.sort!

scc = SCC.new(n)
while (tx, ty, tid = towns.shift)
  tymax = n
  loop do
    town = towns.find { |x, y| y > ty && y <= tymax }
    break unless town
    scc.add_edge(tid, town[2])
    scc.add_edge(town[2], tid)
    tymax = town[1] - 1
  end
end

group_num, ids = scc.send(:scc_ids)
groups = Array.new(group_num) { [] }
ids.each_with_index { |id, i| groups[id] << i }
groups.map!(&:size)

n.times do |k|
  puts groups[ids[k]]
end
