#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)2e6 + 10;
struct point {
  int x, y, idx;
};
int n, m, bl;
point p[MAXN];
int cur = 0;
bool cmp(point p1, point p2) {
  if ((p1.x / bl) == (p2.x / bl)) {
    cur = p1.x / bl;
    if (cur % 2 == 0)
      return p1.y < p2.y;
    else
      return p1.y > p2.y;
  } else
    return p1.x < p2.x;
}
int dist(point p1, point p2) { return (abs(p1.x - p2.x) + abs(p1.y - p2.y)); }
int main() {
  scanf("%d", &n);
  bl = sqrt(n) + 1;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &p[i].x, &p[i].y);
    p[i].idx = i;
  }
  sort(p, p + n, cmp);
  int ans = 0;
  for (int i = 0; i < n; ++i) printf("%d ", p[i].idx + 1);
  return 0;
}
