#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, m, k, c[N], can[N], del[N], done[N];
long long h, dis[N], a[N], s[N];
set<pair<long long, int> > S;
set<pair<int, int> > H;
void recalc() {
  for (int i = 0; i < k; ++i) {
    done[i] = 0;
    dis[i] = 1LL << 60;
  }
  S.insert(make_pair(dis[0] = 0, 0));
  while (!S.empty()) {
    int u = S.begin()->second;
    S.erase(S.begin());
    if (done[u]) continue;
    done[u] = 1;
    for (int i = 1; i <= s[0]; ++i) {
      int v = (s[i] + u) % k;
      if (dis[u] + s[i] < dis[v]) {
        dis[v] = dis[u] + s[i];
        if (dis[v] <= h) S.insert(make_pair(dis[v], v));
      }
    }
  }
  H.clear();
  for (int i = 1; i <= n; ++i)
    if (!del[i] && dis[a[i] % k] <= a[i]) {
      can[i] = 1;
      H.insert(make_pair(c[i], -i));
    } else
      can[i] = 0;
}
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) {
      can[i] = 1;
      H.insert(make_pair(c[i], -i));
    }
  }
  for (int i = 1; i <= m; ++i) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%I64d", &s[++s[0]]);
      recalc();
    }
    if (type == 2) {
      int x, y;
      scanf("%d %d", &x, &y);
      if (can[x]) {
        H.erase(make_pair(c[x], -x));
        c[x] -= y;
        H.insert(make_pair(c[x], -x));
      } else
        c[x] -= y;
    }
    if (type == 3) {
      if (H.empty()) {
        puts("0");
        continue;
      }
      printf("%d\n", H.rbegin()->first);
      del[-H.rbegin()->second] = 1;
      H.erase(--H.end());
    }
  }
}
