#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 500;
const int len = 1e3;
struct Point {
  int x, y, id;
} p[maxn];
bool cmp(Point a, Point b) {
  if (a.x / len != b.x / len) return a.x / len < b.x / len;
  if ((a.x / len) & 1) return a.y < b.y;
  return a.y > b.y;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &p[i].x, &p[i].y);
    p[i].id = i;
  }
  sort(p + 1, p + 1 + n, cmp);
  for (int i = 1; i <= n; i++) cout << p[i].id << ' ';
  return 0;
}
