#include <bits/stdc++.h>
using namespace std;
int n;
int x[1000111], y[1000111];
vector<int> blk[1001];
bool compLess(const int &le, const int &ri) { return (y[le] < y[ri]); }
bool compMore(const int &le, const int &ri) { return (y[le] > y[ri]); }
bool input() {
  if (cin >> n) {
    for (int i = (int)(0), _t = (int)(n - 1); i <= _t; i++) cin >> x[i] >> y[i];
    return true;
  } else {
    return false;
  }
}
void solve() {
  for (int i = (int)(0), _t = (int)(1001 - 1); i <= _t; i++) blk[i].clear();
  for (int i = (int)(0), _t = (int)(n - 1); i <= _t; i++)
    blk[x[i] / 1000].push_back(i);
  for (int i = (int)(0), _t = (int)(1001 - 1); i <= _t; i++) {
    sort((blk[i]).begin(), (blk[i]).end(), (i & 1) ? compMore : compLess);
    for (int j = (int)(0), _t = (int)(((int)((blk[i]).size())) - 1); j <= _t;
         j++)
      cout << (blk[i][j] + 1) << " ";
  }
  cout << endl;
}
int main() {
  ios ::sync_with_stdio(false);
  while (input()) solve();
  return 0;
}
