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