#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9;
long long powm(long long a, long long p, long long m) {
  long long r = 1 % m;
  while (p) {
    if (p & 1) r = r * a % m;
    p >>= 1;
    a = a * a % m;
  }
  return r;
}
struct Node {
  int x, y, i;
};
Node ps[1000000];
bool _cmp(const Node& a, const Node& b) {
  int na = a.x / 1000, nb = b.x / 1000;
  if (na != nb) return na < nb;
  if (na % 2 == 0) return a.y < b.y || a.y == b.y && a.x < b.x;
  return a.y > b.y || a.y == b.y && a.x < b.x;
}
int main() {
  int n, x, y;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &ps[i].x, &ps[i].y);
    ps[i].i = i + 1;
  }
  sort(ps, ps + n, _cmp);
  for (int i = 0; i < n; ++i) printf("%d ", ps[i].i);
  puts("");
  return 0;
}
