#include <bits/stdc++.h>
using namespace std;
int P[1 << 20][2], n;
vector<int> bucket[1 << 10];
int f;
bool cmp(const int& a, const int& b) {
  if (f)
    return P[a][1] > P[b][1];
  else
    return P[a][1] < P[b][1];
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (2); j++) scanf("%d", P[i] + j);
    bucket[P[i][0] / 1000].push_back(i);
  }
  for (int i = 0; i < (1 << 10); i++) {
    sort(bucket[i].begin(), bucket[i].end(), &cmp);
    f = 1 - f;
  }
  bool c = 0;
  for (int i = 0; i < (1 << 10); i++)
    for (auto p : bucket[i]) printf("%s%d", c ? " " : "", p + 1), c = 1;
  puts("");
  return 0;
}
