#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, N = 1e6 + 10, S = 1000;
pair<int, int> A[N];
int n, id[N];
bool cmp(int a, int b) {
  if (A[a].first / S != A[b].first / S) return A[a].first / S < A[b].first / S;
  return (A[a].first / S & 1) ^ (A[a].second < A[b].second);
}
int main() {
  scanf("%d", &n);
  for (int i = (1), i_end = (n); i <= i_end; ++i) {
    id[i] = i;
    scanf("%d%d", &A[i].first, &A[i].second);
  }
  sort(id + 1, id + 1 + n, cmp);
  for (int i = (1), i_end = (n); i <= i_end; ++i) printf("%d ", id[i]);
  return 0;
}
