#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
int B;
bool cmp(const tuple<int, int, int>& a, const tuple<int, int, int>& b) {
  int id1, l1, r1;
  tie(id1, l1, r1) = a;
  int id2, l2, r2;
  tie(id2, l2, r2) = b;
  if (l1 / B != l2 / B)
    return l1 / B < l2 / B;
  else if ((l1 / B) % 2)
    return r1 > r2;
  else
    return r1 < r2;
}
int main() {
  setIO();
  int n;
  cin >> n;
  int mx = 0;
  vector<tuple<int, int, int>> points(n);
  for (int i = (0); i < (n); i++) {
    int x, y;
    cin >> x >> y;
    points[i] = make_tuple(i, x, y);
    mx = max(mx, x);
  }
  B = sqrt(mx + 1);
  sort((points).begin(), (points).end(), cmp);
  for (int i = (0); i < (n); i++) {
    cout << get<0>(points[i]) + 1 << ' ';
  }
  cout << '\n';
  return 0;
}
