#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 1;
int n, first, second;
vector<pair<int, int> > a[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> first >> second;
    a[first / 1000].push_back(make_pair(second, i + 1));
  }
  for (int i = 0; i <= 1000; ++i) {
    sort((a[i]).begin(), (a[i]).end());
    if (i % 2) reverse((a[i]).begin(), (a[i]).end());
    for (int j = 0; j < a[i].size(); ++j) printf("%d ", a[i][j].second);
  }
}
