#include <bits/stdc++.h>
using namespace std;
const int N = 110000;
const int K = 11000;
long long hh, a[N], d[N];
int n, m, k, c[N], p[N], pozc[K];
vector<int> v[K];
vector<long long> ed;
struct cmpp {
  bool operator()(int a, int b) const {
    if (c[a] == c[b]) return a < b;
    return c[a] > c[b];
  }
};
set<int, cmpp> heap;
bool cmp(int aa, int b) { return a[aa] < a[b]; }
void remakeD() {
  int i;
  map<long long, int> h;
  for (i = 1; i < k; ++i) d[i] = hh + 1;
  d[0] = 0;
  h[0] = 0;
  while (!h.empty()) {
    int poz = h.begin()->second;
    h.erase(h.begin());
    for (i = 0; i < ed.size(); ++i) {
      long long cost = ed[i] + d[poz];
      int npoz = (1LL * poz + 1LL * ed[i]) % k;
      if (cost < d[npoz]) {
        if (h.find(d[npoz]) != h.end()) h.erase(h.find(d[npoz]));
        d[npoz] = cost;
        h.insert(pair<int, int>(d[npoz], npoz));
      }
    }
  }
  for (i = 0; i < k; ++i) {
    while (pozc[i] >= 0 && a[v[i][pozc[i]]] >= d[i]) {
      heap.insert(v[i][pozc[i]]);
      --pozc[i];
    }
  }
}
int main() {
  int i;
  cin >> hh >> n >> m >> k;
  for (i = 1; i <= n; ++i) {
    cin >> a[i] >> c[i], p[i] = i;
    --a[i];
  }
  sort(p + 1, p + n + 1, cmp);
  for (i = 1; i <= n; ++i) v[a[p[i]] % k].push_back(p[i]);
  for (i = 0; i < k; ++i) pozc[i] = v[i].size() - 1, d[i] = hh + 1;
  d[0] = 0;
  while (pozc[0] >= 0 && a[v[0][pozc[0]]] >= d[0]) {
    heap.insert(v[0][pozc[0]]);
    --pozc[0];
  }
  for (i = 1; i <= m; ++i) {
    int op, y;
    long long x;
    cin >> op;
    if (op == 1) {
      cin >> x;
      ed.push_back(x);
      remakeD();
    }
    if (op == 2) {
      cin >> x >> y;
      if (heap.find(x) != heap.end()) {
        heap.erase(heap.find(x));
        c[x] -= y;
        heap.insert(x);
        continue;
      }
      c[x] -= y;
    }
    if (op == 3) {
      if (heap.empty()) {
        cout << 0 << "\n";
        continue;
      }
      int aa = *heap.begin();
      cout << c[*heap.begin()] << "\n";
      heap.erase(heap.begin());
      c[aa] = 0;
    }
  }
  return 0;
}
