#include <bits/stdc++.h>
using namespace std;
const int BLOCK = 1000;
struct Point {
  int x, y, idx;
};
int N;
Point pts[1000000 + 1];
bool cmp(Point a, Point b) {
  if (a.x / BLOCK != b.x / BLOCK) return a.x / BLOCK < b.x / BLOCK;
  return (a.x / BLOCK & 1) ? (a.y < b.y) : (a.y > b.y);
}
int main() {
  cin.tie(0)->sync_with_stdio(false);
  cin >> N;
  for (int i = 1; i <= N; i++) cin >> pts[i].x >> pts[i].y, pts[i].idx = i;
  sort(pts + 1, pts + 1 + N, cmp);
  for (int i = 1; i <= N; i++) cout << pts[i].idx << " ";
  cout << "\n";
  return 0;
}
