#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int mod = 1e9 + 7;
const long long int LONGINF = 4e18;
const double eps = 1e-9;
const double PI = 3.1415926535897932384626433832795;
struct p {
  int a, b, n;
};
bool srt(p a, p b) {
  if (a.a / 1000 != b.a / 1000) return a.a < b.a;
  return a.b < b.b;
}
bool srt1(p a, p b) { return a.a < b.a; }
void solve(int n) {
  vector<p> v;
  p a;
  for (int i = 0; i < (n); i++) {
    scanf("%d%d", &a.a, &a.b);
    a.n = i + 1;
    v.push_back(a);
  }
  sort((v).begin(), (v).end(), srt);
  bool rv = false;
  for (int i = 0; i < (n); i++) {
    int l = i, r = i;
    while (r < n && v[l].a / 1000 == v[r].a / 1000) {
      r++;
      i++;
    }
    i--;
    if (rv) {
      reverse(v.begin() + l, v.begin() + r);
      rv = false;
    } else
      rv = true;
  }
  rv = false;
  for (int i = 0; i < (n); i++) {
    int l = i, r = i;
    while (r < n && v[l].a / 1000 == v[r].a / 1000 && v[l].b == v[r].b) {
      r++;
      i++;
    }
    i--;
    sort(v.begin() + l, v.begin() + r, srt1);
    if (rv) {
      reverse(v.begin() + l, v.begin() + r);
      rv = false;
    } else
      rv = true;
  }
  for (int i = 0; i < (n); i++) {
    printf("%d ", v[i].n);
  }
}
int main() {
#pragma comment(linker, "/STACK:268435456")
  int n;
  string s;
  while (scanf("%d", &n) == 1) solve(n);
  return 0;
}
