#include <bits/stdc++.h>
using namespace std;
const int int_inf = 0x3f3f3f3f;
const double double_inf = 1e30;
inline int readint() {
  bool neg = 0;
  char ch, t[11];
  int k = 0;
  while ((ch = getchar()) == ' ' || ch == '\n')
    ;
  neg = ch == '-';
  ch == '-' ? neg = 1 : t[k++] = ch;
  while ((ch = getchar()) >= '0' && ch <= '9') t[k++] = ch;
  int x = 0, y = 1;
  while (k) x += (t[--k] - '0') * y, y *= 10;
  return neg ? -x : x;
}
inline void readstr(char *s) {
  char ch;
  while ((ch = getchar()) == ' ' || ch == '\n')
    ;
  *(s++) = ch;
  while ((ch = getchar()) != ' ' && ch != '\n') *(s++) = ch;
  *s = '\0';
}
inline void writestr(const char *s) {
  while (*s != '\0') putchar(*(s++));
  putchar('\n');
}
inline long long readll() {
  long long x;
  scanf("%lld", &x);
  return x;
}
int debug = 0;
const int maxn = 1e6 + 10;
vector<int> a[maxn];
pair<pair<int, int>, int> b[maxn];
int main() {
  if (debug) freopen("in.txt", "r", stdin);
  int n;
  while (~scanf("%d", &n)) {
    int R = 1000, C = 1000;
    for (int i = 1; i <= n; i++) {
      int x = readint(), y = readint();
      b[i - 1] = make_pair(make_pair(x, y), i);
    }
    sort(b, b + n);
    for (int i = 1; i <= n; i++) {
      int x = b[i - 1].first.first, y = b[i - 1].first.second,
          z = b[i - 1].second;
      int r = x / R, c = y / C;
      if (r == R) --r;
      if (c == C) --c;
      int id = r * C + c;
      a[id].push_back(z);
    }
    int len = R * C;
    int ok = 0;
    for (int i = 0, dx = 1; i < len;) {
      int sz = a[i].size();
      for (int j = 0; j <= sz - 1; j++) {
        if (ok) printf(" ");
        printf("%d", a[i][j]);
        ok = 1;
      }
      if (dx < 0 && i % C == 0 || dx > 0 && i % C == C - 1)
        i += C, dx = -dx;
      else
        i += dx;
    }
    putchar('\n');
  }
  return 0;
}
