#include <bits/stdc++.h>
using namespace std;
bool compare(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
  if (a.second.second == b.second.second) {
    return a.second.first < b.second.first;
  }
  return a.second.second < b.second.second;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<pair<int, pair<int, int> > > bucket[1005];
  int x, y;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    bucket[x / 1000].push_back(make_pair(i, make_pair(x, y)));
  }
  for (int i = 0; i < 1002; i++) {
    sort(bucket[i].begin(), bucket[i].end(), compare);
  }
  for (int i = 0; i < 1002; i++) {
    if (i % 2) {
      for (int j = 0; j < bucket[i].size(); j++) {
        cout << (bucket[i][j].first) + 1 << " ";
      }
    } else {
      for (int j = bucket[i].size() - 1; j >= 0; j--) {
        cout << (bucket[i][j].first) + 1 << " ";
      }
    }
  }
  return 0;
}
