#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
struct Point {
  int x, y;
  int ind;
};
bool cmp(const Point& p1, const Point& p2) {
  if (p1.x / 1000 != p2.x / 1000) return p1.x / 1000 < p2.x / 1000;
  if (p1.x / 1000 % 2 == 0) {
    if (p1.y != p2.y) return p1.y < p2.y;
    return p1.x < p2.x;
  } else {
    if (p1.y != p2.y) return p1.y > p2.y;
    return p1.x < p2.x;
  }
  return false;
}
Point points[1000010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    points[i].ind = i + 1;
    scanf("%d%d", &points[i].x, &points[i].y);
  }
  sort(points, points + n, cmp);
  for (int i = 0; i < n; i++) printf("%d ", points[i].ind);
  return 0;
}
