#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9, K = 1000;
int n;
struct point {
  int y, id;
};
vector<point> b[K];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 0, x, y; i < n; ++i) {
    cin >> x >> y;
    b[(x - 1) / K].push_back({y, i});
  }
  for (int i = 0; i < K; ++i) {
    sort(b[i].begin(), b[i].end(),
         [](const point& x, const point& y) { return (x.y < y.y); });
    for (point x : b[i]) cout << x.id + 1 << ' ';
  }
}
