#include <bits/stdc++.h>
using namespace std;
const int MOD = 10;
const double eps = 1e-5;
const int maxN = 1e5 + 100;
const int maxM = 1;
const long long inf = 1e18;
long long h, n, m, k;
long long A[maxN], C[maxN];
set<pair<long long, long long> > S;
set<pair<long long, long long> > Dij;
bool vis[maxN];
vector<long long> J;
vector<pair<long long, long long> > G[maxN];
long long P[maxN];
inline void calc() {
  fill(P, P + maxN, inf);
  for (long long i = 0; i < J[0]; i++) {
    G[i].clear();
    for (long long j = 1; j < J.size(); j++) {
      G[i].push_back(make_pair((i + J[j]) % J[0], J[j]));
    }
  }
  Dij.insert(make_pair(0, 1));
  while (Dij.size()) {
    pair<long long, long long> t = *(Dij.begin());
    Dij.erase(Dij.begin());
    if (P[t.second] > t.first) {
      P[t.second] = t.first;
      for (long long i = 0; i < G[t.second].size(); i++) {
        if (t.first + G[t.second][i].second < P[G[t.second][i].first])
          Dij.insert(
              make_pair(t.first + G[t.second][i].second, G[t.second][i].first));
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    if (!vis[i]) {
      long long k = A[i] % J[0];
      if (P[k] < A[i]) {
        vis[i] = 1;
        S.insert(make_pair(C[i], -i));
      }
    }
  }
}
inline void init() {
  cin >> h >> n >> m >> k;
  for (long long i = 0; i < n; i++) {
    cin >> A[i] >> C[i];
  }
  J.push_back(k);
  calc();
}
inline void solve() {
  long long q, a, b;
  for (long long i = 0; i < m; i++) {
    cin >> q;
    if (q == 1) {
      cin >> a;
      J.push_back(a);
      sort(J.begin(), J.end());
      calc();
    } else if (q == 2) {
      cin >> a >> b;
      a--;
      if (vis[a]) {
        set<pair<long long, long long> >::iterator it;
        S.erase(S.find(make_pair(C[a], -a)));
        S.insert(make_pair(C[a] - b, -a));
      }
      C[a] -= b;
    } else {
      if (S.size()) {
        cout << (*(--S.end())).first << endl;
        S.erase(--S.end());
      } else
        cout << 0 << endl;
    }
  }
}
int main() {
  init();
  solve();
  return 0;
}
