#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 2, inf = 1e18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<array<long long, 3>> pts[1002];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long x, y;
    cin >> x >> y;
    pts[y / 1000].push_back({x, y, i});
  }
  for (long long i = 0; i <= 1001; i++) {
    if (i & 1)
      sort(pts[i].rbegin(), pts[i].rend());
    else
      sort(pts[i].begin(), pts[i].end());
    for (auto& it : pts[i]) cout << it[2] << ' ';
  }
}
