#include <bits/stdc++.h>
using namespace std;
int n, x[1000005], y[1000005], m;
vector<int> q[1005];
bool cmp(int a, int b) { return y[a] < y[b]; }
int main() {
  m = 1000;
  scanf("%d", &n);
  for (int i = (0); i < (n); i++) {
    scanf("%d %d", &x[i], &y[i]);
    q[x[i] / 1000].push_back(i);
  }
  for (int i = (0); i < (1005); i++) {
    sort(q[i].begin(), q[i].end(), cmp);
    if (i % 2)
      for (int j = (0); j < (q[i].size()); j++) printf("%d\n", q[i][j] + 1);
    else
      for (int j = ((int)q[i].size() - 1); j >= (0); j--)
        printf("%d\n", q[i][j] + 1);
  }
  scanf("\n");
}
