#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<pair<pair<long long, long long>, long long>> sh;
bool cmp(pair<pair<long long, long long>, long long> x,
         pair<pair<long long, long long>, long long> y) {
  if ((x.first.first / 1000) == (y.first.first / 1000)) {
    if ((x.first.first / 1000) & 1)
      return x.first.second < y.first.second;
    else
      return x.first.second > y.first.second;
  } else
    return (x.first.first / 1000) < (y.first.first / 1000);
}
void solve() {
  long long i, j, k, l, r, m, n, a, b, c, d, x, y, z, t;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x >> y;
    sh.push_back({{x, y}, i});
  }
  sort(sh.begin(), sh.end(), cmp);
  for (auto &cv : sh) cout << cv.second << ' ';
  cout << endl;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
