#include <bits/stdc++.h>
using namespace std;
bool fct(const pair<int, pair<int, int> >& p1,
         const pair<int, pair<int, int> >& p2) {
  if (p1.first / 1000 == p2.first / 1000) {
    if ((p1.first / 1000) % 2 == 0)
      return p1.second.first < p2.second.first;
    else
      return p1.second.first > p2.second.first;
  }
  return p1.first / 1000 < p2.first / 1000;
}
int dist(pair<int, int> p1, pair<int, int> p2) {
  return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}
int main() {
  int n;
  scanf("%d", &n);
  vector<pair<int, pair<int, int> > > v;
  for (int i(1); i <= n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    v.push_back(make_pair(a, make_pair(b, i)));
  }
  sort(v.begin(), v.end(), fct);
  for (int i(0); i < n; i++) printf("%d ", (v[i].second).second);
  return 0;
}
