#include <bits/stdc++.h>
using namespace std;
struct point {
  int y, ind;
} tmp;
bool cmpa(point a, point b) { return a.y > b.y; }
bool cmpb(point a, point b) { return a.y < b.y; }
vector<point> v[1003];
int n;
int main() {
  int x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    tmp.y = y;
    tmp.ind = i;
    v[x / 1000].push_back(tmp);
  }
  for (int i = 0; i <= 1000; i++) {
    if (i % 2)
      sort(v[i].begin(), v[i].end(), cmpa);
    else
      sort(v[i].begin(), v[i].end(), cmpb);
    for (int j = 0; j < v[i].size(); j++) printf("%d ", v[i][j].ind);
  }
  puts("");
}
