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