#include <bits/stdc++.h>
using namespace std;
int x[1000004], y[1000004], id[1000003];
int n;
bool func(int i, int j) {
  if (x[i] / 1000 != x[j] / 1000) return x[i] / 1000 < x[j] / 1000;
  if ((x[i] / 1000) % 2)
    return y[i] < y[j];
  else
    return y[i] > y[j];
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> x[i] >> y[i];
    id[i] = i;
  }
  sort(id + 1, id + n + 1, func);
  for (int i = 1; i <= n; ++i) cout << id[i] << " ";
  return 0;
}
