#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& num) {
  bool start = false, neg = false;
  char c;
  num = 0;
  while ((c = getchar()) != EOF) {
    if (c == '-')
      start = neg = true;
    else if (c >= '0' && c <= '9') {
      start = true;
      num = num * 10 + c - '0';
    } else if (start)
      break;
  }
  if (neg) num = -num;
}
struct node {
  int x, y, ps, id;
};
const int BASE = 1000;
const int maxn = (int)(1e6) + 5;
node ai[maxn];
inline bool operator<(node a, node b) {
  if (a.ps != b.ps) return a.ps < b.ps;
  return a.y < b.y;
}
int main() {
  int n;
  read(n);
  for (int i = (1); i <= (n); i++) {
    read(ai[i].x);
    read(ai[i].y);
    ai[i].id = i;
    ai[i].ps = (ai[i].x - 1) / BASE + 1;
  }
  sort(ai + 1, ai + n + 1);
  for (int i = (1); i <= (n); i++) printf("%d ", ai[i].id);
  putchar('\n');
  return 0;
}
