#include <bits/stdc++.h>
const int N = 1000000;
using namespace std;
int x[N], y[N], id[N];
bool cmp(int i, int j) {
  int x1 = x[i] / 1000, x2 = x[j] / 1000;
  return x1 < x2 || (x1 == x2 && (x1 % 2 ? y[i] > y[j] : y[i] < y[j]));
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    id[i] = i;
    scanf("%d%d", &x[i], &y[i]);
  }
  sort(id + 1, id + n + 1, cmp);
  for (int i = 1; i <= n; ++i) printf("%d ", id[i]);
  return 0;
}
