#define _DEBUG
#include "bits/stdc++.h"
#include <atcoder/all>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace atcoder;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;

/*UnionFind*/
struct UnionFind{
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }
  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sizes[root(x)];
  }
};

int main(){
	int N;
	int x[200001],y[200001];
	scan(N);
	set<pint> st1,st2;
	vector<pair<int,pint> > xyi;
    set<pint> st3,st4;
    vector<pair<int,pint> > yxi;
	rep(i,N){
		scan(x[i]>>y[i]);
		xyi.push_back({x[i],{y[i],i}});
        yxi.push_back({y[i],{x[i],i}});
	}
	UnionFind uf(N);
	sort(ALL(xyi));
    sort(ALL(yxi));
	rep(i,N){
		int Y=xyi[i].second.first;
		int I=xyi[i].second.second;
		auto itr=st1.lower_bound(mp(-Y,-INF));
		if(itr!=st1.end()){
			int con=(*itr).second;
			uf.unite(con,I);
		}
		st1.insert(mp(-Y,I));
	}
	brep(i,N){
		int Y=xyi[i].second.first;
		int I=xyi[i].second.second;
		auto itr=st2.lower_bound(mp(Y,-INF));
		if(itr!=st2.end()){
			int con=(*itr).second;
			uf.unite(con,I);
		}
		st2.insert(mp(Y,I));
	}
    rep(i,N){
        int X=yxi[i].second.first;
        int I=yxi[i].second.second;
        auto itr=st3.lower_bound(mp(-X,-INF));
        if(itr!=st3.end()){
            int con=(*itr).second;
            uf.unite(con,I);
        }
        st3.insert(mp(-X,I));
    }
    brep(i,N){
        int X=yxi[i].second.first;
        int I=yxi[i].second.second;
        auto itr=st4.lower_bound(mp(X,-INF));
        if(itr!=st4.end()){
            int con=(*itr).second;
            uf.unite(con,I);
        }
        st4.insert(mp(X,I));
    }
	rep(i,N){
		prin(uf.size(i));
	}
	return 0;
}


Measured memory_bytes: 48608