#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long INFLL = 1001001001001001001LL;
template <typename T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <typename T>
void chmin(T& a, T b) {
  if (a > b) a = b;
}
template <typename T>
void chmax(T& a, T b) {
  if (a < b) a = b;
}
bool exist[100050];
long long pos[100050], val[100050];
long long mv[10050];
set<pair<long long, long long> > calc(long long h, long long n, long long k,
                                      long long ops, long long A[]) {
  for (int i = 0; i < k; ++i) {
    mv[i] = INFLL;
  }
  mv[0] = 0;
  priority_queue<long long> Q;
  Q.push(0);
  while (!Q.empty()) {
    long long v = -Q.top();
    Q.pop();
    long long vk = v % k;
    if (mv[vk] != v) continue;
    for (int i = 0; i < ops; ++i) {
      long long vv = v + A[i];
      long long vvk = vv % k;
      if (mv[vvk] > vv) {
        mv[vvk] = vv;
        Q.push(-vv);
      }
    }
  }
  set<pair<long long, long long> > res;
  for (int i = 0; i < n; ++i) {
    if (exist[i] && mv[pos[i] % k] <= pos[i]) {
      res.insert(make_pair(val[i], -i));
    }
  }
  return res;
}
int main() {
  long long h, A[24];
  long long n, m, k, ops = 0;
  cin >> h >> n >> m >> k;
  for (int i = 0; i < n; ++i) {
    cin >> pos[i] >> val[i];
    exist[i] = true;
    --pos[i];
  }
  set<pair<long long, long long> > ts = calc(h, n, k, ops, A);
  for (int i = 0; i < m; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      cin >> A[ops++];
      ts = calc(h, n, k, ops, A);
    } else if (t == 2) {
      long long x, y;
      cin >> x >> y;
      --x;
      bool found = ts.find(make_pair(val[x], -x)) != ts.end();
      if (found) ts.erase(make_pair(val[x], -x));
      val[x] -= y;
      if (found) ts.insert(make_pair(val[x], -x));
    } else if (t == 3) {
      if (ts.empty()) {
        cout << 0 << endl;
      } else {
        cout << ts.rbegin()->first << endl;
        exist[-ts.rbegin()->second] = false;
        ts.erase(*ts.rbegin());
      }
    }
  }
  return 0;
}
