#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

int cc = 0;
bool vis[200005];

vector<int> t;
void DFS(vector<int> adj[] , int s)
{
    vis[s] = 1;
    cc++;
    t.push_back(s);
    for(int i=0 ;i<adj[s].size() ;i++)
    {
        if(!vis[adj[s][i]])
            DFS(adj,adj[s][i]);
    }
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;

    vector<pair<pair<int,int>,int>> p;
    for(int i=0 ; i<n ; i++)
    {
        ll x,y;
        cin >> x >> y;
        p.push_back({{x,y},i});
    }
    sort(p.begin(),p.end());
    vector<pair<int,int>> p2;
    for(int i=0 ; i<n ; i++)
        p2.push_back({p[i].first.second,p[i].second});

    vector<int> adj[n];
    stack < pair<int,int > > s,s2;

      s.push(p2[0]);
      for (int i = 1; i < n; i++)
      {

        if (s.empty()) {
          s.push(p2[i]);
          continue;
        }
        while (!s.empty() && s.top().first < p2[i].first)
        {
            adj[s.top().second].push_back(p2[i].second);
            adj[p2[i].second].push_back(s.top().second);
            s.pop();
        }
        s.push(p2[i]);
      }

      for (int i = 0; i < n; i++)
      {
          while (!s2.empty() && s2.top().first > p2[i].first)
            s2.pop();
        if(!s2.empty())
        {
              adj[p2[i].second].push_back( s2.top().second);
              adj[s2.top().second].push_back(p2[i].second );
        }
        s2.push(p2[i]);
      }

      //int[] min = new int[n];

    int Min[n];
    Min[n - 1] = p2[n - 1].first;
    for (int i = n - 2; i >= 0; i--)
        Min[i] = max(p2[i].first, Min[i + 1]);
    // calculate results
    //int[] results = new int[n];
    int results[n];
    results[n - 1] = -1;
    for (int i = n - 2; i >= 0; i--) {
        int left = i; // after the binary search, A[left] would be the answer
        int right = n - 1;
        while (left < right) {
            int mid = left + (right - left + 1) / 2;
            if (Min[mid] > p2[i].first)
                left = mid;
            else
                right = mid - 1;
            if (Min[left] > p2[i].first)
            {
                results[i] = Min[left];
                adj[p2[i].second].push_back(p2[left].second);
                adj[p2[left].second].push_back(p2[i].second);
            }
            else
                results[i] = -1;
        }
    }

   /* Min[0] = p2[0].first;
     //Min[n - 1] = p2[n - 1].first;
    for (int i = 1; i<n; i++)
        Min[i] = min(p2[i].first, Min[i - 1]);

    // calculate results
    //int[] results = new int[n];
//    int results[n];
    results[0] = -1;
    for (int i = 1; i<n ; i++) {
        int left = i; // after the binary search, A[left] would be the answer
        int right = n - 1;
        while (left < right) {
            int mid = left + (right - left + 1) / 2;
            if (Min[mid] < p2[i].first)
                left = mid;
            else
                right = mid - 1;
            if (Min[left] < p2[i].first)
            {
                results[i] = Min[left];
                adj[p2[i].second].push_back(p2[left].second);
                adj[p2[left].second].push_back(p2[i].second);
            }
            else
                results[i] = -1;
        }
    }

    for(int i=0 ; i<n ; i++)
        cout << p2[i].first << " ";
    cout << endl;

    for(int i=0 ; i<n ; i++)
        cout << results[i] << " ";
    cout << endl;*/

      int ans[n]={0};
      for(int i=0 ; i<n ;i++)
      {
          if(!vis[i])
          {
              cc = 0;
              DFS(adj,i);
              for(int j=0 ; j<t.size() ; j++)
                ans[t[j]] = cc;
              t.clear();
          }
      }
      for(int i=0 ; i<n ;i++)
      {
          if(ans[i] == 0)
            cout << 1 << "\n";
          else
            cout << ans[i] << "\n";
      }
      return 0;
}


Measured memory_bytes: 65008