#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> sor(1001);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    sor[y / 1000].push_back({x, i + 1});
  }
  for (int i = 0; i < 1001; i++) {
    if (i % 2 == 0)
      sort(sor[i].begin(), sor[i].end());
    else
      sort(sor[i].rbegin(), sor[i].rend());
    for (auto j : sor[i]) cout << j.second << " ";
  }
}
