#include <bits/stdc++.h>
using namespace std;
struct point {
  int x;
  int y;
  int pos;
  point() {}
  point(int _x, int _y, int _pos) : x(_x), y(_y), pos(_pos) {}
};
vector<point> rectangles[1001];
bool cmp1(point a, point b) { return a.y < b.y; }
bool cmp2(point a, point b) { return a.y > b.y; }
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    rectangles[a / 1001].push_back(point(a, b, i + 1));
  }
  for (int i = 0; i < 1001; i++) {
    if (rectangles[i].size() > 0) {
      sort(rectangles[i].begin(), rectangles[i].end(), i % 2 ? cmp2 : cmp1);
    }
  }
  for (int i = 0; i < 1001; i++) {
    for (int j = 0, d = rectangles[i].size(); j < d; j++) {
      printf("%d ", rectangles[i][j].pos);
    }
  }
  printf("\n");
  return 0;
}
