#include <bits/stdc++.h>
using namespace std;
int n, x, y;
vector<pair<int, int> > grp[1003];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &x, &y);
    grp[x / 1000].push_back({y, i + 1});
  }
  for (int i = 0; i < 1001; i++) {
    sort(grp[i].begin(), grp[i].end());
    if (i & 1) {
      for (int j = grp[i].size() - 1; j >= 0; j--)
        cout << grp[i][j].second << ' ';
    } else
      for (auto j : grp[i]) cout << j.second << ' ';
  }
}
