#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  int n;
  cin >> n;
  vector<pair<int, int> > arr[1001];
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    arr[x / 1000].push_back(make_pair(y, i));
  }
  for (int i = 0; i < 1001; i++)
    if (arr[i].size() > 1) sort(arr[i].begin(), arr[i].end());
  bool flag = 0;
  for (int i = 0; i < 1001; i++) {
    if (arr[i].size()) {
      flag = (!flag);
      if (flag)
        for (int j = 0; j < arr[i].size(); j++) cout << arr[i][j].second << ' ';
      else
        for (int j = arr[i].size() - 1; j >= 0; j--)
          cout << arr[i][j].second << ' ';
    }
  }
}
