#include <bits/stdc++.h>
using namespace std;
int a[1050000], b[1050000];
vector<int> block[1000 + 10][1000 + 10];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i], &b[i]);
    block[a[i] / 1000][b[i] / 1000].push_back(i);
  }
  bool flag = 0;
  for (int i = 0; i <= 1000; i++) {
    bool change = false;
    if (flag) {
      for (int j = 0; j <= 1000; j++) {
        for (int k = 0; k < block[i][j].size(); k++) {
          printf("%d ", block[i][j][k] + 1);
          change = true;
        }
      }
    } else {
      for (int j = 1000; j >= 0; j--) {
        for (int k = 0; k < block[i][j].size(); k++) {
          printf("%d ", block[i][j][k] + 1);
          change = true;
        }
      }
    }
    if (change) flag = 1 - flag;
  }
}
