#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int K = 1e4 + 7;
const long long INF = 1e18 + 7;
long long h, a[N], dist[K];
int n, m, k, c[N];
vector<pair<int, long long>> adj[K];
bool taken[N];
void AddMethod(long long x) {
  for (int u = 0; u < k; u++) {
    int v = (u + x) % k;
    adj[u].push_back({v, x});
  }
}
void Dijkstra() {
  for (int i = 0; i < k; i++) dist[i] = INF;
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      pq;
  dist[0] = 0;
  pq.push({dist[0], 0});
  while (!pq.empty()) {
    int u = pq.top().second;
    long long curDist = pq.top().first;
    pq.pop();
    if (dist[u] != curDist) continue;
    for (auto e : adj[u]) {
      int v = e.first;
      long long c = e.second;
      if (dist[v] > dist[u] + c) {
        dist[v] = dist[u] + c;
        pq.push({dist[v], v});
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> h >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> c[i];
    a[i]--;
  }
  Dijkstra();
  set<pair<long long, int>> canTake;
  for (int i = 1; i <= n; i++)
    if (dist[a[i] % k] <= a[i]) canTake.insert({c[i], -i});
  for (int i = 1; i <= m; i++) {
    int type;
    cin >> type;
    if (type == 1) {
      long long x;
      cin >> x;
      AddMethod(x);
      Dijkstra();
      canTake.clear();
      for (int j = 1; j <= n; j++)
        if (dist[a[j] % k] <= a[j] && !taken[j]) canTake.insert({c[j], -j});
    } else if (type == 2) {
      int x, y;
      cin >> x >> y;
      if (canTake.find({c[x], -x}) != canTake.end()) {
        canTake.erase({c[x], -x});
        canTake.insert({c[x] - y, -x});
      }
      c[x] -= y;
    } else {
      if (canTake.empty()) {
        cout << 0 << '\n';
        continue;
      }
      auto p = *(--canTake.end());
      canTake.erase(p);
      taken[-p.second] = 1;
      cout << p.first << '\n';
    }
  }
  return 0;
}
