#include <bits/stdc++.h>
using namespace std;
struct dian {
  int x, y, i;
} a[1000005];
int m = 0;
void print(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
inline int read() {
  register int x = 0, ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x;
}
int n, nn;
bool cmp(dian x, dian y) {
  int xl = x.x / nn, yl = y.x / nn;
  if (xl > yl) return 0;
  if (xl < yl) return 1;
  if (xl & 1)
    return x.y > y.y;
  else
    return x.y < y.y;
}
void rd() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    a[i].x = read();
    a[i].y = read();
    a[i].i = i;
    m = max(m, a[i].x);
    m = max(m, a[i].y);
  }
  nn = sqrt(m) + 1;
  sort(a + 1, a + n + 1, cmp);
}
signed main() {
  rd();
  for (int i = 1; i <= n; i++) {
    print(a[i].i);
    printf(" ");
  }
  return 0;
}
