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