#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100010;
const int MaxK = 10010;
long long h, INF;
int n, m, k;
long long a[MaxN];
int c[MaxN], u[MaxN];
vector<int> p[MaxK];
vector<pair<long long, long long> > v[MaxK];
set<pair<int, int> > H;
void addway(long long x) {
  for (int i = 0; i < k; ++i)
    v[i].push_back(pair<long long, long long>((i + x) % k, x));
}
long long d[MaxK];
void build() {
  for (int i = 0; i < k; ++i) d[i] = INF;
  d[1] = 1;
  priority_queue<pair<long long, long long> > Q;
  Q.push(pair<long long, long long>(-1, 1));
  while (!Q.empty()) {
    long long x = Q.top().second;
    long long y = -Q.top().first;
    Q.pop();
    if (d[x] != y) continue;
    for (vector<pair<long long, long long> >::iterator it = v[x].begin();
         it != v[x].end(); ++it)
      if (d[it->first] > y + it->second)
        Q.push(pair<long long, long long>(-(d[it->first] = y + it->second),
                                          it->first));
  }
  H.clear();
  H.insert(pair<int, int>(0, 0));
  for (int i = 0; i < k; ++i)
    for (vector<int>::iterator it = p[i].begin(); it != p[i].end(); ++it)
      if (a[*it] >= d[i]) {
        u[*it] = 1;
        H.insert(pair<int, int>(c[*it], -*it));
      }
}
int main() {
  cin >> h >> n >> m >> k;
  INF = h + 10;
  for (int i = 1; i <= n; ++i) {
    scanf("%I64d%d", &a[i], &c[i]);
    p[a[i] % k].push_back(i);
  }
  build();
  while (m--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      long long x;
      scanf("%I64d", &x);
      addway(x);
      build();
    } else if (t == 2) {
      int x, y;
      scanf("%d%d", &x, &y);
      if (u[x]) {
        H.erase(pair<int, int>(c[x], -x));
        H.insert(pair<int, int>(c[x] - y, -x));
      }
      c[x] -= y;
    } else {
      set<pair<int, int> >::iterator it = --H.end();
      printf("%d\n", it->first);
      c[-it->second] = 0;
      if (it->second) H.erase(it);
    }
  }
  return 0;
}
