#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > p[1005];
int x, y;
bool ord(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", &x);
    scanf("%d", &y);
    p[x / 1000].push_back(make_pair(y, i));
  }
  for (int i = 0; i < 1001; i++) {
    if (i % 2 == 0)
      sort((p[i]).begin(), (p[i]).end());
    else
      sort((p[i]).begin(), (p[i]).end(), ord);
  }
  for (int i = 0; i < 1001; i++) {
    for (int j = 0; j < p[i].size(); j++) cout << p[i][j].second << " ";
  }
  cout << endl;
}
