#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
int n, first, second;
struct my {
  int first, second, z;
} a[N];
inline char cmp(my a, my b) {
  return a.first < b.first ||
         (a.first == b.first && ((a.second < b.second && a.first % 2) ||
                                 (a.second > b.second && a.first % 2 == 0)));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first >> a[i].second;
    a[i].z = i + 1;
    a[i].first /= 1000;
  }
  sort(a, a + n, cmp);
  for (int i = 0; i < n; ++i) printf("%d ", a[i].z);
}
