#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int> > v;
bool gr(pair<pair<int, int>, int> i, pair<pair<int, int>, int> j) {
  if (i.first.second != j.first.second)
    return (i.first.second < j.first.second);
  if (i.first.second % 2 == 0) return (i.first.first < j.first.first);
  return (i.first.first > j.first.first);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    y = y / 1000;
    v.push_back(make_pair(make_pair(x, y), i));
  }
  sort(v.begin(), v.end(), gr);
  for (int j = 0; j < v.size(); j++) printf("%d ", v[j].second + 1);
  return 0;
}
