#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/numeric.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;
	template<class T>using pair = std::pair<T, T>;

	struct max_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	constexpr max_t max;
	constexpr min_t min;

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min();

	template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;
	
	template<class T>constexpr T pow(T val, std::uint64_t p)
	{
		auto ret = T(1);
		auto s = 1ULL;
		for (auto i = 0; i < 63; ++i, s <<= 1)
		{
			if (p & s)
			{
				ret *= val;
			}
			val *= val;
		}
		return ret;
	}
}

class union_find
{
	mutable std::vector<std::optional<index_t>> parent;
	std::vector<index_t> rank, elem;
	std::set<index_t> tops;
	std::size_t sz;
public:
	union_find(std::size_t N) :parent(N), rank(N), elem(N, 1), tops(), sz(N)
	{
		for (index_t i = 0; i < N; ++i)
		{
			tops.emplace(i);
		}
	}
	index_t find(index_t a)const
	{
		if (!parent[a])
		{
			return a;
		}
		else
		{
			return *(parent[a] = find(*parent[a]));
		}
	}
	void merge(index_t a, index_t b)
	{
		auto x = find(a);
		auto y = find(b);
		if (x != y)
		{
			--sz;
			if (rank[x] < rank[y])
			{
				tops.erase(x);
				parent[x] = y;
				elem[y] += elem[x];
			}
			else if (rank[y] < rank[x])
			{
				tops.erase(y);
				parent[y] = x;
				elem[x] += elem[y];
			}
			else
			{
				tops.erase(y);
				parent[y] = x;
				elem[x] += elem[y];
				++rank[x];
			}
		}
	}
	std::size_t size(std::optional<index_t> index = std::nullopt)const
	{
		return index ? elem[find(*index)] : sz;
	}
	auto begin()const
	{
		return tops.begin();
	}
	auto end()const
	{
		return tops.end();
	}
};

void Main()
{
	std::size_t N;
	std::cin >> N;
	std::vector<lib::pair<index_t>> points(N);
	std::vector<index_t> inverse(N);
	for (auto& [x, y] : points)
	{
		std::cin >> x >> y;
		--x; --y;
		inverse[y] = x;
	}
	auto sorted = points;
	boost::sort(sorted, std::greater<>());
	union_find uf(N);
	std::set<index_t> ys;
	for (auto [x, y] : sorted)
	{
		auto first = ys.emplace(y).first;
		for (auto ite = std::next(first); ite != ys.end(); ++ite)
		{
			uf.merge(x, inverse[*ite]);
		}
		ys.erase(first, std::prev(ys.end()));
	}
	for (auto [x, y] : points)
	{
		std::cout << uf.size(x) << std::endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 26700