#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
struct Point {
  int x, y, id;
} p[N];
bool cmp(Point p1, Point p2) { return p1.y < p2.y; }
vector<Point> G[1005];
int main() {
  int n, ct;
  while (~scanf("%d", &n)) {
    for (int i = 0; i < 1005; i++) G[i].clear();
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &p[i].x, &p[i].y);
      p[i].id = i;
      G[p[i].x / 1000].push_back(p[i]);
    }
    ct = 0;
    bool go = true;
    for (int i = 0; i < 1005; i++) {
      sort(G[i].begin(), G[i].end(), cmp);
      int len = G[i].size();
      if (go)
        for (int j = 0; j < len; j++) {
          printf("%d", G[i][j].id);
          ct++;
          printf("%c", (n == ct) ? '\n' : ' ');
        }
      else
        for (int j = len - 1; j >= 0; j--) {
          printf("%d", G[i][j].id);
          ct++;
          printf("%c", (n == ct) ? '\n' : ' ');
        }
      (go == true) ? go = false : go = true;
    }
  }
  return 0;
}
