#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v[1005];
int main() {
  int n;
  scanf(" %d", &n);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf(" %d %d", &a, &b);
    v[a / 1000].push_back(make_pair(b, i + 1));
  }
  for (int i = 0; i < 1002; i += 2) sort(v[i].begin(), v[i].end());
  for (int i = 1; i < 1002; i += 2) sort(v[i].rbegin(), v[i].rend());
  bool space = false;
  for (int i = 0; i < 1002; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      if (space) printf(" ");
      space = true;
      printf("%d", v[i][j].second);
    }
  }
  return 0;
}
