#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535897932;
const double EPS = 1e-15;
const long long mod = 1e+9 + 7;
const int INF = 1001001001;
struct RNG {
  mt19937 mt;
  RNG() : mt(chrono::steady_clock::now().time_since_epoch().count()) {}
  int operator()(int a, int b) {
    uniform_int_distribution<int> dist(a, b - 1);
    return dist(mt);
  }
  int operator()(int b) { return (*this)(0, b); }
};
struct Timer {
  chrono::high_resolution_clock::time_point st;
  Timer() { reset(); }
  void reset() { st = chrono::high_resolution_clock::now(); }
  chrono::milliseconds::rep elapsed() {
    auto ed = chrono::high_resolution_clock::now();
    return chrono::duration_cast<chrono::milliseconds>(ed - st).count();
  }
};
int N, W, K, V;
int c[1005], v[1005];
vector<pair<int, int>> classification[6];
tuple<vector<int>, int> random_search() {
  vector<vector<int>> board_color(8001, vector<int>(8, -1));
  vector<vector<int>> board_value(8001, vector<int>(8, -1));
  vector<int> next(8, 0);
  RNG rd;
  vector<int> res;
  for (int i = 0; i < N; ++i) {
    int select = rd(8);
    board_color[next[select]][select] = c[i];
    board_value[next[select]][select] = v[i];
    ++next[select];
    res.push_back(select);
  }
  int total_score = 0;
  for (int i = 0; i < 8000; ++i) {
    vector<int> score(8, 0);
    bool flag = true;
    for (int j = 0; j < 8; ++j) {
      if (board_color[i][j] == -1) {
        flag = false;
        break;
      }
      score[board_color[i][j]] += board_value[i][j];
    }
    if (!flag) break;
    total_score += *max_element(score.begin(), score.end());
  }
  return make_tuple(res, total_score);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  Timer timekeeper;
  const double T = 1950;
  cin >> N >> W >> K >> V;
  for (int i = 0; i < N; ++i) {
    cin >> c[i] >> v[i];
    classification[c[i]].push_back(pair<int, int>(v[i], i));
  }
  for (int i = 0; i < K; ++i) {
    sort(classification[i].begin(), classification[i].end(),
         greater<pair<int, int>>());
  }
  double time;
  vector<int> res(N);
  int total_score = 0;
  while ((time = timekeeper.elapsed()) <= T) {
    int score;
    vector<int> order(N);
    tie(order, score) = random_search();
    if (score > total_score) {
      score = total_score;
      res = order;
    }
  }
  for (int i = 0; i < N; ++i) cout << res[i] << "\n";
}
