#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int prime = 999983;
const int INF = 0x3f3f3f3f;
const int INFF = 1e9;
const double pi = 3.141592653589793;
const double inf = 1e18;
const double eps = 1e-6;
const int mod = 1e9 + 7;
inline int read_int() {
  int ret = 0;
  char tmp;
  while (!isdigit(tmp = getchar()))
    ;
  do {
    ret = (ret << 3) + (ret << 1) + tmp - '0';
  } while (isdigit(tmp = getchar()));
  return ret;
}
struct Node {
  int x, y;
  int id, d;
  bool operator<(const Node &a) const {
    if (id == a.id && id % 2 == 1) return y > a.y;
    if (id == a.id && id % 2 == 0) return y < a.y;
    return id < a.id;
  }
} node[1000005];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      node[i] = (Node){a, b, a / 1000, i + 1};
    }
    sort(node, node + n);
    for (int i = 0; i < n; i++) {
      printf("%d", node[i].d);
      if (i == n - 1)
        printf("\n");
      else
        printf(" ");
    }
  }
  return 0;
}
