#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
pair<pair<int, int>, int> P[1000000 + 10];
int main() {
  int n = read();
  int x, y;
  for (int i = 1; i <= n; i++) {
    x = read();
    y = read();
    P[i].first.first = x / 1005;
    P[i].first.second = y;
    P[i].second = i;
  }
  sort(P + 1, P + n + 1);
  for (int i = 1; i <= n; i++) {
    cout << P[i].second << " ";
  }
  return 0;
}
