#include <bits/stdc++.h>
using namespace std;
template <class T>
void show(const vector<T> &a) {
  for (T x : a) cout << x << " ";
  cout << '\n';
}
const long long N = 1e5 + 50, oo = 1e18 + 500;
const long long mod = 998244353;
const long long M2 = 1000000093, x2 = 27162;
const long long M1 = 1000000087, x1 = 241;
const long double eps = 1e-18, PI = 2 * acos(0.0);
long long cnt = 0;
vector<vector<long long> > g;
vector<long long> visit;
vector<long long> djkstra(vector<long long> ks, long long k) {
  vector<long long> d(k, oo);
  d[1 % k] = 1;
  set<pair<long long, long long> > st;
  for (long long i = 0; i < k; i++) {
    st.insert({d[i], i});
  }
  while (((long long)(st.size()))) {
    pair<long long, long long> pr = *st.begin();
    st.erase(pr);
    long long u = pr.second;
    for (auto x : ks) {
      long long v = (u + x) % k;
      if (d[v] > d[u] + x) {
        st.erase({d[v], v});
        d[v] = d[u] + x;
        st.insert({d[v], v});
      }
    }
  }
  return d;
}
signed main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  long long h, n, m, k;
  cin >> h >> n >> m >> k;
  vector<long long> cost(n);
  vector<vector<pair<long long, long long> > > notused(k);
  for (long long i = 0; i < n; i++) {
    long long pos, c;
    cin >> pos >> c;
    cost[i] = c;
    notused[pos % k].push_back({pos, i});
  }
  set<pair<long long, long long> > used;
  vector<long long> ks;
  vector<long long> d = djkstra(ks, k);
  for (long long i = 0; i < k; i++) {
    sort(notused[i].begin(), notused[i].end());
    while (((long long)(notused[i].size())) &&
           notused[i].back().first >= d[i]) {
      pair<long long, long long> pr = notused[i].back();
      used.insert({cost[pr.second], -pr.second});
      notused[i].pop_back();
    }
  }
  while (m--) {
    long long type;
    cin >> type;
    if (type == 1) {
      long long x;
      cin >> x;
      ks.push_back(x);
      d = djkstra(ks, k);
      for (long long i = 0; i < k; i++) {
        while (((long long)(notused[i].size())) &&
               notused[i].back().first >= d[i]) {
          pair<long long, long long> pr = notused[i].back();
          used.insert({cost[pr.second], -pr.second});
          notused[i].pop_back();
        }
      }
    }
    if (type == 2) {
      long long i, y;
      cin >> i >> y;
      i--;
      if (used.count({cost[i], -i})) {
        used.erase({cost[i], -i});
        used.insert({cost[i] - y, -i});
      }
      cost[i] -= y;
    }
    if (type == 3) {
      if (((long long)(used.size()))) {
        pair<long long, long long> pr = *used.rbegin();
        cout << pr.first << '\n';
        used.erase(pr);
      } else {
        cout << 0 << '\n';
      }
    }
  }
}
