#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<long long, long long>, long long> > v[1001];
int main() {
  int n;
  cin >> n;
  long long p = -1ll;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    if ((x / 1000) % 2)
      p = 1ll;
    else
      p = -1ll;
    v[x / 1000].push_back(make_pair(make_pair(y * p, x), i));
  }
  long long ans = 0;
  for (int i = 0; i < 1001; i++) {
    sort(v[i].begin(), v[i].end());
    for (int j = 0; j < v[i].size(); j++) cout << v[i][j].second + 1 << ' ';
  }
  return 0;
}
