#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int N = 1e6 + 5;
long long int t, n, m, a[N] = {0};
vector<pair<long long int, pair<long long int, long long int> > > v;
bool cmp(const pair<long long int, pair<long long int, long long int> > &a,
         const pair<long long int, pair<long long int, long long int> > &b) {
  if ((a.second.first / 1000) != (b.second.first / 1000))
    return (a.second.first / 1000) < (b.second.first / 1000);
  if ((a.second.first / 1000) % 2) return a.second.second < b.second.second;
  return a.second.second > b.second.second;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i, j, k, x, y;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x >> y;
    v.push_back({i, {x, y}});
  }
  sort(v.begin(), v.end(), cmp);
  for (auto it : v) cout << it.first << " ";
  return 0;
}
