#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 15;
const int maxk = 10000 + 15;
const long long oo = 1000000000000000000ll;
struct Bj {
  int key1, key2;
  Bj() { key1 = key2 = 0; }
  Bj(int key1, int key2) : key1(key1), key2(key2) {}
};
const bool operator<(const Bj &a, const Bj &b) {
  if (a.key1 == b.key1) return a.key2 > b.key2;
  return a.key1 < b.key1;
}
priority_queue<Bj> que;
long long h, a[maxn];
int n, m, k, c[maxn];
long long minn[maxk];
int shang[25], ys[25], sum;
bool boo[maxk];
int hh, tt, line[maxk];
int main() {
  scanf("%I64d%d%d%d", &h, &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d%d", &a[i], &c[i]);
    a[i]--;
    if (a[i] % k == 0) que.push(Bj(c[i], i));
  }
  for (int i = 1; i < k; i++) minn[i] = oo;
  minn[0] = 0;
  int od;
  while (m--) {
    scanf("%d", &od);
    if (od == 1) {
      long long x;
      scanf("%I64d", &x);
      shang[++sum] = x / k;
      ys[sum] = x % k;
      hh = 0;
      tt = k - 1;
      int now = k;
      for (int i = 0; i < k; i++) line[i] = i;
      memset(boo, true, sizeof(boo));
      for (; now > 0; now--, boo[line[hh]] = false, hh = (hh + 1) % k) {
        for (int i = 1; i <= sum; i++) {
          long long x = minn[line[hh]] + shang[i];
          int y = line[hh] + ys[i];
          if (y >= k) y -= k, x++;
          if (x < minn[y]) {
            minn[y] = x;
            if (!boo[y]) {
              now++;
              tt = (tt + 1) % k;
              line[tt] = y;
              boo[y] = true;
            }
          }
        }
      }
      while (!que.empty()) que.pop();
      for (int i = 1; i <= n; i++)
        if (minn[a[i] % k] <= a[i] / k && c[i] != 0) {
          que.push(Bj(c[i], i));
        }
    } else if (od == 2) {
      int x, y;
      scanf("%d%d", &x, &y);
      c[x] -= y;
      if (minn[a[x] % k] <= a[x] / k) que.push(Bj(c[x], x));
    } else if (od == 3) {
      bool boo = false;
      while (!que.empty()) {
        Bj g = que.top();
        que.pop();
        if (c[g.key2] == g.key1) {
          printf("%d\n", g.key1);
          c[g.key2] = 0;
          boo = true;
          break;
        }
      }
      if (!boo) printf("0\n");
    }
  }
  return 0;
}
