#include <bits/stdc++.h>
using namespace std;
int OK = 1;
const int INF = 0x3f3f3f3f;
const int maxn = 1001000;
struct node {
  int x, y, id;
} pt[maxn];
bool cmp(node a, node b) {
  if (a.x != b.x) return a.x < b.x;
  return a.y < b.y;
}
int arr[maxn];
int main() {
  int n;
  cin >> n;
  int tot = 0, flag = 0;
  vector<node> ans[1100];
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &pt[i].x, &pt[i].y);
    pt[i].id = i + 1;
    ans[pt[i].y / 1000].push_back(pt[i]);
  }
  for (int i = 0; i < 1005; ++i) {
    if (ans[i].empty()) continue;
    sort(ans[i].begin(), ans[i].end(), cmp);
    if (flag) reverse(ans[i].begin(), ans[i].end());
    flag ^= 1;
    for (auto jj : ans[i]) arr[tot++] = jj.id;
  }
  for (int i = 0; i < n; i++) printf("%d ", arr[i]);
  return 0;
}
