#include <bits/stdc++.h>
using namespace std;
struct cp {
  int x, y;
} a[1000100];
vector<int> r[1010][1010];
bool cmp(int i, int j) {
  if (a[i].x == a[j].x) return a[i].y < a[j].y;
  return (a[i].x < a[j].x);
}
bool cmp2(int i, int j) {
  if (a[i].x == a[j].x) return a[i].y < a[j].y;
  return (a[i].x > a[j].x);
}
int n, i, j;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &a[i].x, &a[i].y);
    r[a[i].x / 1000][a[i].y / 1000].push_back(i);
  }
  for (i = 0; i <= 1000; i++) {
    if (i & 1)
      for (j = 1000; j >= 0; j--) {
        sort(r[i][j].begin(), r[i][j].end(), cmp2);
        for (vector<int>::iterator it = r[i][j].begin(); it != r[i][j].end();
             it++)
          printf("%d ", *it);
      }
    else
      for (j = 0; j <= 1000; j++) {
        sort(r[i][j].begin(), r[i][j].end(), cmp);
        for (vector<int>::iterator it = r[i][j].begin(); it != r[i][j].end();
             it++)
          printf("%d ", *it);
      }
  }
}
