#include <bits/stdc++.h>
using namespace std;
long long h;
int n, m, k, c[100005];
long long a[100005];
vector<long long> setofk;
bool done[100005];
long long d[10004];
set<pair<long long, int> > heap;
void dijkstra() {
  for (int i = 0; i < k; i++) d[i] = (long long)1e18;
  d[1] = 1;
  heap.clear();
  heap.insert(make_pair(1, 1));
  while (!heap.empty()) {
    int u = heap.begin()->second;
    heap.erase(heap.begin());
    for (int i = 0; i < setofk.size(); i++) {
      long long dis = d[u] + setofk[i];
      int v = dis % k;
      if (dis < d[v]) {
        if (d[v] != (long long)1e18) heap.erase(make_pair(d[v], v));
        d[v] = dis;
        heap.insert(make_pair(d[v], v));
      }
    }
  }
}
struct node {
  int val, ind;
} seg[(1 << 17) << 1];
void init() {
  for (int i = (1 << 17) - 1; i > 0; i--) {
    seg[i].val = max(seg[i << 1].val, seg[i << 1 | 1].val);
    if (seg[i].val == seg[i << 1].val)
      seg[i].ind = seg[i << 1].ind;
    else
      seg[i].ind = seg[i << 1 | 1].ind;
  }
}
void update(int ind, int inc) {
  seg[(1 << 17) + ind].val += inc;
  for (int i = ((1 << 17) + ind) >> 1; i > 0; i >>= 1) {
    seg[i].val = max(seg[i << 1].val, seg[i << 1 | 1].val);
    if (seg[i].val == seg[i << 1].val)
      seg[i].ind = seg[i << 1].ind;
    else
      seg[i].ind = seg[i << 1 | 1].ind;
  }
}
void solve1(long long x) {
  setofk.push_back(x);
  dijkstra();
  for (int i = 1; i <= n; i++) {
    int mod = a[i] % k;
    if (a[i] >= d[mod] and !done[i]) {
      done[i] = 1;
      update(i, c[i]);
    }
  }
}
void solve2(int x, int y) {
  c[x] -= y;
  if (done[x]) update(x, -y);
}
int solve3() {
  int ans = seg[1].val;
  int i = seg[1].ind;
  update(i, -c[i]);
  return ans;
}
int main() {
  cin >> h >> n >> m >> k;
  for (int i = 1; i <= n; i++) cin >> a[i] >> c[i];
  setofk.push_back(k);
  dijkstra();
  for (int i = 1; i <= n; i++) {
    int mod = a[i] % k;
    if (a[i] >= d[mod]) {
      done[i] = 1;
      update(i, c[i]);
    }
  }
  for (int i = 0; i <= n; i++) seg[(1 << 17) + i].ind = i;
  init();
  while (m--) {
    int id;
    cin >> id;
    if (id == 1) {
      long long x;
      cin >> x;
      solve1(x);
    } else if (id == 2) {
      int x, y;
      cin >> x >> y;
      solve2(x, y);
    } else
      cout << solve3() << "\n";
  }
  return 0;
}
