#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1e-11;
int n;
pair<int, int> a[1000100];
vector<pair<int, int> > v[1010];
pair<pair<int, int>, int> t;
int main() {
  cout << setiosflags(ios::fixed) << setprecision(10);
  cin >> n;
  for (int i = 0; i < (n); i++) {
    scanf("%d%d", &a[i].first, &a[i].second);
    v[a[i].first / 1001].push_back(make_pair(a[i].second, i + 1));
  }
  for (int i = 0; i < (1010); i++) {
    sort(v[i].begin(), v[i].end());
    if (i % 2) reverse(v[i].begin(), v[i].end());
  }
  for (int i = 0; i < (1010); i++)
    for (int j = 0; j < (v[i].size()); j++) printf("%d ", v[i][j].second);
  return 0;
}
