#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<tuple<int, int, int> > pts;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    pts.push_back(make_tuple(i + 1, x, y));
  }
  std::sort(begin(pts), end(pts),
            [](tuple<int, int, int> const &t1, tuple<int, int, int> const &t2) {
              int slot1 = get<1>(t1) == 1000000 ? 999 : get<1>(t1) / 1000;
              int slot2 = get<1>(t2) == 1000000 ? 999 : get<1>(t2) / 1000;
              if (slot1 != slot2) {
                return slot1 < slot2;
              }
              if (slot1 % 2 != 0) {
                return get<2>(t1) > get<2>(t2);
              }
              return get<2>(t1) < get<2>(t2);
            });
  vector<int> res;
  for (auto t : pts) {
    cout << get<0>(t) << " ";
  }
}
