#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 100;
int x[N], y[N], n, block = 1000, id[N];
bool cmp(int a, int b) {
  int s = x[a] / block, f = x[b] / block;
  if (s != f) return s < f;
  if (s & 1)
    return y[a] < y[b];
  else
    return y[a] > y[b];
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &x[i], &y[i]);
    id[i] = i;
  }
  sort(id, id + n, cmp);
  for (int i = 0; i < n; ++i) {
    printf("%d ", id[i] + 1);
  }
  return 0;
}
