#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7, sqr = 1000;
int a[N], cnt[N];
long long ans, ANS[N];
inline bool mo(pair<pair<int, int>, int> x, pair<pair<int, int>, int> y) {
  if (x.first.first / sqr == y.first.first / sqr)
    return x.first.second < y.first.second;
  return x.first.first < y.first.first;
}
vector<pair<pair<int, int>, int> > Q;
int32_t main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    Q.push_back({{l + 1, r + 1}, i});
  }
  sort(Q.begin(), Q.end(), mo);
  for (int i = 0; i < Q.size(); i++) cout << Q[i].second + 1 << " ";
  cout << endl;
}
