#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
const int MAXK = 10000;
const long long INFLL = 1012345678901234567LL;
long long h, a[MAXN];
int n, m, k, c[MAXN];
priority_queue<pair<int, int> > heap;
vector<long long> K;
long long dist[MAXK];
priority_queue<long long, vector<long long>, greater<long long> > q;
void refreshHeap() {
  dist[0] = 0;
  for (int i = (1); i < (k); i++) dist[i] = INFLL;
  for (q.push(0); !q.empty();) {
    long long d = q.top();
    q.pop();
    if (dist[d % k] != d) continue;
    for (typeof((K).begin()) it = (K).begin(); it != (K).end(); it++)
      if (d + *it < h) {
        long long newD = d + *it;
        int idx = newD % k;
        if (dist[idx] > newD) {
          dist[idx] = newD;
          q.push(newD);
        }
      }
  }
  for (; !heap.empty(); heap.pop())
    ;
  for (int i = (0); i < (n); i++)
    if (c[i] && dist[a[i] % k] <= a[i]) heap.push(make_pair(c[i], -i));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> h >> n >> m >> k;
  for (int i = (0); i < (n); i++) {
    cin >> a[i] >> c[i];
    a[i]--;
  }
  refreshHeap();
  for (int _ = (0); _ < (m); _++) {
    int op;
    cin >> op;
    if (op == 1) {
      long long x;
      cin >> x;
      K.push_back(x);
      refreshHeap();
    } else if (op == 2) {
      int x, y;
      cin >> x >> y;
      c[x - 1] -= y;
    } else {
      if (heap.empty()) {
        cout << 0 << endl;
      } else {
        while (true) {
          int value = heap.top().first, idx = -heap.top().second;
          if (c[idx] != value) {
            heap.pop();
            heap.push(make_pair(c[idx], -idx));
          } else {
            break;
          }
        }
        cout << heap.top().first << endl;
        c[-heap.top().second] = 0;
        heap.pop();
      }
    }
  }
  return 0;
}
