#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
const int M = 1000;
pair<int, int> a[N];
vector<int> A[N];
int n;
bool cm(int i, int j) { return a[i].second < a[j].second; }
bool cmi(int i, int j) { return a[i].second > a[j].second; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &a[i].first, &a[i].second);
  for (int i = 1; i <= n; ++i) A[a[i].first / M].push_back(i);
  for (int i = 0; i <= M; ++i)
    if (!A[i].empty()) sort(A[i].begin(), A[i].end(), (i % 2) ? cm : cmi);
  for (int i = 0; i <= M; ++i)
    if (!A[i].empty())
      for (vector<int>::iterator j = A[i].begin(); j != A[i].end(); ++j)
        printf("%d ", *j);
  return 0;
}
