#include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> a[1000005];
int ans[1000005];
bool cmp(int i, int j) {
  if (a[i].first != a[j].first) return a[i].first < a[j].first;
  return (a[i].first & 1) ? a[i].second > a[j].second
                          : a[i].second < a[j].second;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d %d", &a[i].first, &a[i].second), a[i].first /= 1000, ans[i] = i;
  sort(ans + 1, ans + n + 1, cmp);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}
