#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
pair<pair<long long, long long>, int> a[N];
bool comp(pair<pair<long long, long long>, int> a,
          pair<pair<long long, long long>, int> b) {
  if (a.first.first != b.first.first) return a.first.first < b.first.first;
  return a.first.first % 2 ? a.first.second < b.first.second
                           : a.first.second > b.first.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a[i].first.first = x / 1000;
    a[i].first.second = y;
    a[i].second = i + 1;
  }
  sort(a, a + n, comp);
  for (int i = 0; i < n; i++) cout << a[i].second << " ";
}
