#include <bits/stdc++.h>
using namespace std;
struct atp {
  int id, x, y;
} a[2000000];
int n, ma;
bool cmp(atp a, atp b) { return a.y < b.y; }
bool cmp1(atp a, atp b) { return a.x < b.x; }
bool cmp2(atp a, atp b) { return a.x > b.x; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i].x, &a[i].y);
    a[i].id = i;
  }
  sort(a + 1, a + n + 1, cmp);
  ma = a[n].y;
  int l = 1, r = 1;
  for (int i = 0; i * 1000 <= ma; i++) {
    while (r <= n && a[r].y < (i + 1) * 1000) r++;
    if (i % 2)
      sort(a + l, a + r, cmp1);
    else
      sort(a + l, a + r, cmp2);
    l = r;
  }
  for (int i = 1; i <= n; i++) {
    printf("%d%c", a[i].id, i == n ? '\n' : ' ');
  }
  return 0;
}
