#include <bits/stdc++.h>
using namespace std;
vector<pair<int, pair<int, int> > > a[1003];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    int h = y / 1000;
    a[h].push_back(make_pair(x, make_pair(y, i)));
  }
  for (int i = 0; i <= 1000; i++) {
    sort(a[i].begin(), a[i].end());
  }
  for (int i = 0; i <= 1000; i++) {
    if (i % 2 == 0)
      for (int j = 0; j < a[i].size(); j++)
        cout << a[i][j].second.second << " ";
    else {
      for (int j = a[i].size() - 1; j >= 0; j--)
        cout << a[i][j].second.second << " ";
    }
  }
  cout << '\n';
}
