#include <bits/stdc++.h>
const int N = 1000000;
int n = 0;
int p[N + 100];
struct node {
  long long y;
  long long x;
  long long k;
  int i;
};
node nodes[N + 100];
void get_ll(long long& r) {
  r = 0LL;
  char c = 0;
  do {
    c = getchar();
  } while (c == ' ' || c == '\n' || c == '\t');
  do {
    r *= 10LL;
    r += (c - '0');
    c = getchar();
  } while (c >= '0' && c <= '9');
}
bool comp(const node& a, const node& b) {
  if (a.k != b.k) return a.k < b.k;
  if (a.k % 2 == 0) return a.y < b.y;
  return a.y > b.y;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    get_ll(nodes[i].x);
    get_ll(nodes[i].y);
    nodes[i].k = nodes[i].x / 1000LL;
    nodes[i].i = i + 1;
  }
  std::sort(nodes, nodes + n, comp);
  for (int i = 0; i < n; i++) printf("%d ", nodes[i].i);
  printf("\n");
  return 0;
}
