#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

struct Node {
	int x, y, index;
	bool operator<(const Node&n)const {
		return make_pair(x, y) < make_pair(n.x, n.y);
	}
};

class Segment_Tree {
	vector<long long int>v;
	int num;
	long long int ret;
	bool is_min;
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		if (is_min) {
			v[place] = min(Update(place * 2), Update(place * 2 + 1));
			return v[place];
		}
		v[place] = max(Update(place * 2), Update(place * 2 + 1));
		return v[place];
	}
public:
	Segment_Tree(int n, bool min) {
		n++;
		num = 1;
		while (num < n * 2) {
			num *= 2;
		}
		is_min = min;
		if (min) {
			v.resize(num, MOD*MOD);
		}
		else v.resize(num, -MOD * MOD);
	}
	void Insert(int place, long long int num, bool update) {
		place += v.size() / 2;
		v[place] = num;
		if (!update)return;
		place /= 2;
		while (place) {
			if (is_min)v[place] = min(v[place * 2], v[place * 2 + 1]);
			else v[place] = max(v[place * 2], v[place * 2 + 1]);
			place /= 2;
		}
	}
	void TopDown() {
		Update(1);
	}
	long long int RMQ(int a, int b) {
		if (is_min)ret = INT_MAX;
		else ret = INT_MIN;
		if (is_min) {
			b++;
			for (a += num / 2, b += num / 2; a < b; a >>= 1, b >>= 1) {
				if (a & 1)ret = min(ret, v[a++]);
				if (b & 1)ret = min(ret, v[--b]);
			}
		}
		else {
			b++;
			for (a += num / 2, b += num / 2; a < b; a >>= 1, b >>= 1) {
				if (a & 1)ret = max(ret, v[a++]);
				if (b & 1)ret = max(ret, v[--b]);
			}
		}
		return ret;
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N;
	vector<Node>v(N);
	vector<int>y_to_x(N);
	vector<int>x(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i].x >> v[i].y;
		v[i].x--, v[i].y--;
		v[i].index = i;
		x[i] = y_to_x[v[i].y] = v[i].x;
	}
	sort(v.begin(), v.end());
	vector<int>ans(N);
	Segment_Tree msg(N, true);
	Segment_Tree Msg(N, false);
	for (int i = 0; i < N; i++) {
		msg.Insert(i, v[i].y, false);
		Msg.Insert(i, v[i].y, false);
	}
	msg.TopDown();
	Msg.TopDown();
	for (auto i : v) {
		if (ans[i.index])continue;
		int cnt = 1;
		queue<int>Q;
		vector<int>box;
		Q.push(i.x);
		box.push_back(i.index);
		msg.Insert(i.x, MOD, true);
		Msg.Insert(i.x, -MOD, true);
		while (!Q.empty()) {
			int cx = Q.front();
			int cy = v[cx].y;
			Q.pop();
			while (Msg.RMQ(cx + 1, N - 1) > cy) {
				cnt++;
				auto xp = y_to_x[Msg.RMQ(cx + 1, N - 1)];
				Q.push(xp);
				box.push_back(v[xp].index);
				Msg.Insert(xp, -MOD, true);
				msg.Insert(xp, MOD, true);
			}
			while (msg.RMQ(0, cx - 1) < cy) {
				cnt++;
				auto xp = y_to_x[msg.RMQ(0, cx - 1)];
				Q.push(xp);
				box.push_back(v[xp].index);
				msg.Insert(xp, MOD, true);
				Msg.Insert(xp, -MOD, true);
			}
		}
		for (auto j : box) {
			ans[j] = cnt;
		}
	}
	for (auto i : ans)cout << i << endl;
}

Measured memory_bytes: 17860