#include <bits/stdc++.h>
using namespace std;
int n, i, j, x, y;
vector<pair<int, int> > v[1005];
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    v[x / 1000].push_back(make_pair(y, i));
  }
  for (i = 0; i <= 1000; i++) sort(v[i].begin(), v[i].end());
  for (i = 1; i <= 1000; i += 2) reverse(v[i].begin(), v[i].end());
  for (i = 0; i <= 1000; i++)
    for (j = 0; j < v[i].size(); j++) printf("%d ", v[i][j].second);
  return 0;
}
