#include <bits/stdc++.h>
using namespace std;
vector<int> V[20005];
int a[1000005], b[1000005];
bool cmp1(int x, int y) { return b[x] < b[y]; }
bool cmp2(int x, int y) { return b[x] > b[y]; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]), scanf("%d", &b[i]);
    V[a[i] / 1000].push_back(i);
  }
  for (int i = 0; i <= 1000; i++) {
    if (i % 2)
      sort(V[i].begin(), V[i].end(), cmp1);
    else
      sort(V[i].begin(), V[i].end(), cmp2);
    for (int j = 0; j < V[i].size(); j++) printf("%d ", V[i][j]);
  }
  cout << endl;
}
