#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x;
  int y;
  int num;
};
bool cmp(Point x1, Point x2) { return x1.y < x2.y; }
int main() {
  int n;
  scanf("%d", &n);
  array<vector<struct Point>, 1001> groups;
  struct Point q;
  int x, y;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &x, &y);
    q.x = x;
    q.y = y;
    q.num = i + 1;
    groups[x / 1000].push_back(q);
  }
  for (int i = 0; i < 1001; i++) {
    sort(groups[i].begin(), groups[i].end(), cmp);
  }
  bool reverse = false;
  for (int i = 0; i < 1001; i++) {
    if (reverse == false) {
      for (auto it = groups[i].begin(); it != groups[i].end(); ++it) {
        printf("%d ", (*it).num);
      }
      reverse = true;
    } else {
      for (auto it = groups[i].rbegin(); it != groups[i].rend(); ++it) {
        printf("%d ", (*it).num);
      }
      reverse = false;
    }
  }
  printf("\n");
  return 0;
}
