#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > out[1005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    pair<int, int> a;
    scanf("%d %d", &a.first, &a.second);
    out[a.first / 1000].push_back(make_pair(a.second, i));
  }
  for (int i = 0; i <= 1000; i++) {
    sort((out[i]).begin(), (out[i]).end());
    if (i & 1) reverse((out[i]).begin(), (out[i]).end());
    for (int j = 0; j < ((int)(out[i]).size()); j++)
      printf("%d ", out[i][j].second);
  }
  printf("\n");
  return 0;
}
