#include <bits/stdc++.h>
using namespace std;
int k, n, m;
long long h;
vector<long long> pos, dist;
vector<int> val;
set<pair<int, int> > cells;
vector<long long> shifts;
int recalc() {
  cells.clear();
  dist.assign(k, -1LL);
  dist[1] = 1LL;
  priority_queue<pair<long long, int> > q;
  q.push(make_pair(-dist[1], 1));
  while (!q.empty()) {
    pair<long long, int> cur = q.top();
    q.pop();
    if (dist[cur.second] < -cur.first) continue;
    for (__typeof((shifts).begin()) i = (shifts).begin(); i != (shifts).end();
         ++i) {
      int go = (int)((*i + cur.second) % k);
      if (dist[go] == -1 || dist[go] > (-cur.first + *i)) {
        dist[go] = (-cur.first + *i);
        q.push(make_pair(-dist[go], go));
      }
    }
  }
  for (int i = 0; i < n; ++i)
    if (val[i] != 0 && dist[pos[i] % k] != -1LL && dist[pos[i] % k] <= pos[i])
      cells.insert(make_pair(-val[i], i));
  return 0;
}
int decrease(int i, int dec) {
  pair<long long, int> corr = make_pair(-val[i], i);
  val[i] -= dec;
  if (cells.count(corr) != 0) {
    cells.erase(corr);
    cells.insert(make_pair(-val[i], i));
  }
  return 0;
}
int getMax() {
  if (cells.empty()) {
    cout << "0\n";
    return 0;
  }
  pair<int, int> ans = *(cells.begin());
  cells.erase(ans);
  val[ans.second] = 0;
  cout << -ans.first << '\n';
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> h >> n >> m >> k;
  dist.resize(k);
  pos.resize(n);
  val.resize(n);
  for (int i = 0; i < n; ++i) cin >> pos[i] >> val[i];
  recalc();
  for (int i = 0; i < m; ++i) {
    int type, x, y;
    long long hx;
    cin >> type;
    if (type == 3)
      getMax();
    else if (type == 2) {
      cin >> x >> y;
      decrease(x - 1, y);
    } else {
      cin >> hx;
      shifts.push_back(hx);
      recalc();
    }
  }
  return 0;
}
