#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

struct UnionFind
{
    vector<int> par, rank, sz, maxv;
    UnionFind(int N) : par(N), rank(N), sz(N), maxv(N)
    {
        REP(i, N)
        {
            par[i] = i;  //the parent of the node
            rank[i] = 0; //the rank of the tree
            sz[i] = 1;
            maxv[i] = 1;
        }
    }
    int find(int x)
    { //Find the root of x
        if (par[x] == x)
        {
            return x;
        }
        else
        {
            return par[x] = find(par[x]);
        }
    }
    int size(int x)
    {
        return sz[find(x)];
    }
    int maxval(int x)
    {
        return maxv[find(x)];
    }
    void unite(int x, int y)
    { //Unite (the set of x) and (the set of y)
        x = find(x), y = find(y);
        if (x == y)
            return;
        if (rank[x] < rank[y])
        { //larger rank is above
            sz[y] += sz[x];
            maxv[y] = max(maxv[y], maxv[x]);
            par[x] = y;
        }
        else
        {
            sz[x] += sz[y];
            maxv[x] = max(maxv[y], maxv[x]);
            par[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
};

void solve() {
    ll n;
    cin >> n;
    vector<pair<pll, int>> xy(n);
    REP(i,n) {
        cin >> xy[i].FI.FI >> xy[i].FI.SE;
        xy[i].SE = i;
        /* xy[i].FI--;xy[i].SE--; */
    }
    sort(ALL(xy));
    /* REP(i,n) { */
    /*     cout << xy[i].FI.FI << " " << xy[i].FI.SE << " " << xy[i].SE << endl; */
    /* } */
    UnionFind d(n);
    REP(i, n) {
        d.maxv[i] = xy[i].FI.SE;
    }
    map<int, int> ma;
    REP(i,n) {
        ma[xy[i].FI.SE] = i;
    }
    int rbd = n;
    map<ll, ll> maxvec;
    vector<bool> vis(n, false);
    for (auto ite = ma.begin(); ite != ma.end(); ++ite) {
        int idx = ite->second;
        if (vis[idx]) continue;
        vis[idx] = true;
        ll nowidx = idx+1, maxv = ite->FI;
        while (nowidx <= n - 1 && (!vis[nowidx]) ) {
            vis[nowidx] = true;
            d.unite(idx, nowidx);
            maxv = max(maxv, xy[nowidx].FI.SE);
            ++nowidx;
        }
        if (nowidx != n) {
            if (ite->FI < d.maxval(nowidx) ) {
                d.unite(idx, nowidx);
            }
        }
    }

    /* ll maxv = xy[n-1].FI.SE, minv = xy[n-1].FI.SE; */
    /* int maxidx = n - 1; */
    /* vector<pair<int,pint>> mato; */
    /* bool flag = false; */
    /* IREP(i,n-1) { */
    /*     if (xy[i].FI.SE < maxv) { */
    /*         d.unite(i, maxidx); */
    /*         minv = min(minv, xy[i].FI.SE); */
    /*     } else { */
    /*         mato.push_back(make_pair(maxidx, make_pair(maxv, minv))); */
    /*         maxv = xy[i].FI.SE; */
    /*         minv = xy[i].FI.SE; */
    /*     } */
    /* } */
    /* mato.push_back(make_pair(maxidx, make_pair(maxv, minv))); */
    /* reverse(ALL(mato)); */
    /* int minidx */
    /* REP(i, mato.size() - 1) { */
    /*     if (mato[i].SE.SE < mato[i+1].SE.FI) { */
    /*         d.unite(mato[i].FI, mato[i+1].FI); */
    /*     } */
    /* } */


    vint ans(n, 0);
    REP(i, n) {
        /* cout << endl; */
        /* cout << xy[i].SE << endl; */
        ans[xy[i].SE] = d.size(i);
    }
    REP(i,n) {
        cout << ans[i] << endl;
    }
}

int main() {
    solve();
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}



Measured memory_bytes: 21252