#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int> > H;
int n, m, k, type, x, y, L, ed[25], f[100005 * 20], c[100005];
long long d[100005], a[100005], data[25], z;
bool b[100005];
int main() {
  scanf("%*I64d%d%d%d", &n, &m, &k);
  memset(d, 1, sizeof(d)), d[1] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d%d", a + i, c + i);
    if (a[i] % k == 1) H.push(make_pair(c[i], -i));
  }
  while (m--) {
    scanf("%d", &type);
    while (type == 3) {
      if (H.empty()) {
        puts("0");
        break;
      }
      pair<int, int> o = H.top();
      H.pop();
      x = -o.second, y = o.first;
      if (c[x] == y) {
        printf("%d\n", y), c[x] = 0;
        break;
      }
    }
    if (type == 2) {
      scanf("%d%d", &x, &y), c[x] -= y;
      if (d[a[x] % k] <= a[x] / k) H.push(make_pair(c[x], -x));
    }
    if (type == 1) {
      scanf("%I64d", &z);
      data[++L] = z / k, ed[L] = z % k;
      int h = 0, t = 0;
      for (int i = 1; i <= k; i++) f[++t] = i - 1;
      while (h < t) {
        x = f[++h], b[x] = 0;
        for (int i = 1; i <= L; i++) {
          y = x + ed[i], z = d[x] + data[i];
          if (y >= k) y -= k, z++;
          if (z < d[y]) {
            d[y] = z;
            if (!b[y]) b[y] = 1, f[++t] = y;
          }
        }
      }
      while (!H.empty()) H.pop();
      for (int i = 1; i <= n; i++) {
        if (d[a[i] % k] <= a[i] / k && c[i]) H.push(make_pair(c[i], -i));
      }
    }
  }
  return 0;
}
