#include <bits/stdc++.h>
using namespace std;
int a[10000];
map<int, int> mm;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<int, int> > v[1001];
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    int num = x / 1000;
    v[num].push_back(make_pair(y, i + 1));
  }
  for (int i = 0; i < 1001; i++) {
    sort(v[i].begin(), v[i].end());
    if (i % 2) reverse(v[i].begin(), v[i].end());
    for (int j = 0; j < v[i].size(); j++) cout << v[i][j].second << ' ';
  }
  return 0;
}
