lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
Inf = 10 ** 7

towns = []
for i in 1..N do
  towns[i-1] = (Inf ** 2) * lines[i][0] + Inf * lines[i][1] + i
end

towns.sort!

sorted = []
inv_y = []
rev_id = []
for i in 1..N do
  sorted[i-1] = []
  sorted[i-1][0] = towns[i-1] / (Inf ** 2)
  sorted[i-1][1] = (towns[i-1] % (Inf ** 2)) / Inf
  sorted[i-1][2] = towns[i-1] % Inf
  inv_y[sorted[i-1][1]-1] = i
  rev_id[sorted[i-1][2]-1] = i
end

current_min = N-1
nums = []
for i in 1..N do
  nums[i-1] = 0
end

for i in 1..N do
  if nums[i-1] == 0 then
    num = 1
    if sorted[i-1][1] < current_min then
      num += current_min - sorted[i-1][1]
    end
    nums[i-1] = num
    for j in sorted[i-1][1]+1..current_min do
      nums[sorted[inv_y[j-1]-1][0]-1] = num
     # puts j
    end
    if sorted[i-1][1] <= current_min then
      current_min = sorted[i-1][1]-1
    end
  end
end

for i in 1..N do
  id = rev_id[i-1]
  puts nums[id-1]
end