#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
struct point {
  long long x, y, i;
};
bool cmp(const point &i, const point &j) {
  long long blockI = i.x / 1000;
  long long blockJ = j.x / 1000;
  if (blockI == blockJ) {
    if (blockI % 2 == 0) return i.y < j.y;
    return i.y > j.y;
  }
  return blockI < blockJ;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<point> arr(n);
  for (long long i = 0; i < n; ++i) {
    cin >> arr[i].x >> arr[i].y;
    arr[i].i = i + 1;
  }
  sort(arr.begin(), arr.end(), cmp);
  for (long long i = 0; i < n; ++i) {
    cout << arr[i].i << " ";
  }
}
