#include <bits/stdc++.h>
using namespace std;
struct point {
  long long x, y;
  int id;
} p[1234560];
int n;
vector<int> lr, ud;
long long cal(point a, point b) { return abs(a.x - b.x) + abs(a.y - b.y); }
bool cmp1(point a, point b) {
  if (a.x != b.x)
    return a.x < b.x;
  else
    return a.y < b.y;
}
bool cmp2(point a, point b) {
  if (a.y != b.y)
    return a.y < b.y;
  else
    return a.x < b.x;
}
bool cmp3(point a, point b) {
  if (a.y != b.y)
    return a.y > b.y;
  else
    return a.x < b.x;
}
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) {
      scanf("%I64d%I64d", &p[i].x, &p[i].y);
      p[i].id = i + 1;
    }
    sort(p, p + n, cmp1);
    long long sum1 = 0;
    long long pu = 0;
    for (long long i = 0; i < 1000; i++) {
      long long pt = pu;
      while (p[pu].x <= 1000ll * (i + 1) && pu < n) pu++;
      if (i & 1)
        sort(p + pt, p + pu, cmp3);
      else
        sort(p + pt, p + pu, cmp2);
      for (long long j = pt; j < pu; j++) {
        printf("%d ", p[j].id);
      }
    }
    cout << endl;
  }
  return 0;
}
