#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
struct cmp {
  bool operator()(pair<long long int, long long int> p1,
                  pair<long long int, long long int> p2) {
    if (p1.first != p2.first) return p1.first > p2.first;
    return p1.second < p2.second;
  }
};
vector<pair<long long int, long long int>> v[N], g[N];
map<long long int, long long int> mp;
long long int wh[N], co[N], p[N], d[N], nd[N], n, m, k, h;
void SPAS() {
  fill(nd, nd + 10010, 1e18 + 2);
  nd[1] = 1;
  set<pair<long long int, long long int>> s;
  s.insert(make_pair(1, 1));
  while (s.size() > 0) {
    pair<long long int, long long int> p = *s.begin();
    for (auto u : g[p.second]) {
      if (nd[u.first] > nd[p.second] + u.second) {
        s.erase(make_pair(nd[u.first], u.first));
        nd[u.first] = nd[p.second] + u.second;
        s.insert(make_pair(nd[u.first], u.first));
      }
    }
    s.erase(p);
  }
  for (int i = 0; i < k; i++) {
    d[i] = nd[i];
  }
}
int main() {
  cin >> h >> n >> m >> k;
  set<pair<long long int, long long int>, cmp> s;
  for (int i = 0; i < n; i++) {
    cin >> wh[i] >> co[i];
    mp[wh[i]] = co[i];
    v[wh[i] % k].emplace_back(make_pair(wh[i], i));
    if (wh[i] % k == 1) s.insert(make_pair(co[i], i));
  }
  for (int i = 0; i < k; i++) {
    sort(v[i].begin(), v[i].end());
    p[i] = (int)v[i].size() - 1;
    d[i] = 1e18 + 2;
  }
  d[1] = 1;
  p[1] = -1;
  while (m--) {
    long long int q;
    cin >> q;
    if (q == 1) {
      long long int x;
      cin >> x;
      for (int i = 0; i < k; i++) {
        g[i].emplace_back(make_pair((i + x) % k, x));
      }
      SPAS();
      for (int i = 0; i < k; i++) {
        if (p[i] == -1) continue;
        while (v[i][p[i]].first >= d[i]) {
          s.insert(make_pair(co[v[i][p[i]].second], v[i][p[i]].second));
          p[i]--;
          if (p[i] == -1) break;
        }
      }
    }
    if (q == 2) {
      long long int x, y;
      cin >> x >> y;
      x--;
      if (s.find(make_pair(co[x], x)) != s.end()) {
        s.erase(make_pair(co[x], x));
        co[x] -= y;
        s.insert(make_pair(co[x], x));
      } else
        co[x] -= y;
    }
    if (q == 3) {
      if (s.size() == 0) {
        cout << 0 << '\n';
        continue;
      }
      cout << (*s.begin()).first << '\n';
      s.erase(*s.begin());
    }
  }
}
