#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y, id;
};
node A[1000100];
int ans[1000100];
vector<int> P[1200];
int cmp1(node a, node b) { return a.x < b.x; }
int cmp2(int a, int b) { return A[a].y < A[b].y; }
const int Base = 1000;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d %d", &A[i].x, &A[i].y), A[i].id = i;
  sort(A + 1, A + n + 1, cmp1);
  for (int i = 1; i <= n; i++) {
    P[(A[i].x - 1) / Base + 1].push_back(i);
  }
  int k = 0;
  for (int i = 0; i <= 1018; i++) {
    sort(P[i].begin(), P[i].end(), cmp2);
    for (int j = 0; j < P[i].size(); j++) {
      ans[++k] = A[P[i][j]].id;
    }
  }
  for (int i = 1; i <= k; i++) printf("%d ", ans[i]);
  return 0;
}
