#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000 + 20, SQ = 1000;
int n, l[N], r[N], tmp[N];
bool cmp(int i, int j) {
  if (l[i] / SQ != l[j] / SQ) return l[i] < l[j];
  if (~(l[i] / SQ) & 1)
    return r[i] < r[j];
  else
    return r[i] > r[j];
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d%d", &l[i], &r[i]);
  for (int i = 0; i < n; i++) tmp[i] = i;
  sort(tmp, tmp + n, cmp);
  for (int i = 0; i < n; i++) printf("%d ", tmp[i] + 1);
}
