#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > p[1005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    p[x / 1000].push_back({y, i});
  }
  for (int i = 0; i <= 1000; i++) {
    sort(p[i].begin(), p[i].end());
    if (i % 2) reverse(p[i].begin(), p[i].end());
    for (auto& x : p[i]) {
      printf("%d ", x.second);
    }
  }
  printf("\n");
}
