#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int> > m[1000];
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    m[b / 1000].push_back(make_pair(make_pair(a, b), i + 1));
  }
  bool ok = 0;
  for (int i = 0; i <= 1000; i++) {
    if (ok)
      sort(m[i].begin(), m[i].end());
    else
      sort(m[i].rbegin(), m[i].rend());
    ok = !ok;
    for (int k = 0; k < m[i].size(); k++) {
      cout << m[i][k].second << " ";
    }
  }
  cout << "\n";
  return 0;
}
