#include <bits/stdc++.h>
using namespace std;
const long double EPS = 0.000001;
const long long N = 100001;
const long long INF = 1e18;
long long p[N], c[N], reached[N], n, m, k, v, e, nv;
map<long long, pair<long long, long long> > mp;
set<pair<long double, long long> > dj;
set<pair<long long, long long> > st;
vector<long long> mod[N], ms;
long double dist[N], d, cost;
void add(long long newe) {
  fill(dist, dist + k, INF);
  dist[1] = 0;
  ms.push_back(newe);
  dj.clear();
  for (long long i = 0; i < k; i++) dj.insert(make_pair(dist[i], i));
  while (dj.size()) {
    v = dj.begin()->second;
    d = dj.begin()->first;
    dj.erase(*dj.begin());
    for (long long i = 0; i < ms.size(); i++) {
      e = ms[i];
      nv = e + v;
      cost = (long double)e / k;
      if (dist[nv % k] > d + cost) {
        dj.erase(make_pair(dist[nv % k], nv % k));
        dist[nv % k] = d + cost;
        dj.insert(make_pair(dist[nv % k], nv % k));
      }
    }
  }
  st.clear();
  for (long long i = 0; i < k; i++)
    if (dist[i] != INF)
      for (long long j = 0; j < mod[i].size(); j++)
        if (dist[i] * k + EPS < p[mod[i][j]]) {
          st.insert(make_pair(c[mod[i][j]], n - mod[i][j]));
          reached[mod[i][j]] = 1;
        }
}
void update(long long p, long long x) {
  st.erase(mp[p]);
  st.insert(make_pair(x, mp[p].second));
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> n >> m >> k;
  for (long long i = 0; i < n; i++) {
    cin >> p[i] >> c[i];
    mod[p[i] % k].push_back(i);
    mp[p[i]] = make_pair(c[i], n - i);
    if (p[i] % k == 1) st.insert(mp[p[i]]);
  }
  add(k);
  long long t, x, y;
  while (m--) {
    cin >> t;
    if (t == 1) {
      cin >> x;
      add(x);
    } else if (t == 2) {
      cin >> x >> y;
      x--;
      if (reached[x]) update(p[x], c[x] - y);
      c[x] -= y;
      mp[p[x]] = make_pair(c[x], n - x);
    } else if (st.empty())
      cout << 0 << endl;
    else {
      pair<long long, long long> best = *st.rbegin();
      x = n - best.second;
      cout << best.first << endl;
      update(p[x], 0);
      c[x] = 0;
      mp[p[x]] = make_pair(0, n - x);
    }
  }
}
