#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int M = 505;
const int nmax = 4e3 + 5;
const long long inf = 1e9;
const int mod = 1e9 + 7;
const int B = 31;
const long long BOUND = 25 * 1e8;
struct node {
  int i;
  int first, second;
  int c;
  int p;
} a[N];
bool f(node a, node b) {
  return (a.c < b.c) ||
         (a.c == b.c && (!a.p ? a.second < b.second : a.second > b.second));
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> ans;
  for (int i = 0; i < n; ++i) {
    int first, second;
    scanf("%d%d", &first, &second);
    int c = first / 1000;
    a[i] = {i + 1, first, second, c, c % 2};
  }
  sort(a, a + n, f);
  for (int i = 0; i < n; ++i) printf("%d ", a[i].i);
  printf("\n");
  return 0;
}
