#include <bits/stdc++.h>
using namespace std;
const int inf = 0x20202020;
const long long mod = 1000000007;
const double eps = 1e-9;
const double pi = 3.1415926535897932384626;
const int DX[] = {1, 0, -1, 0}, DY[] = {0, 1, 0, -1};
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long powmod(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 101000;
set<pair<long long, int> > hp, hp2;
bool vis[N], del[N];
long long a[N], dis[N], h;
int c[N];
int n, m, k;
int ty, p1, p2;
long long p3;
void resolve(long long p) {
  hp2.clear();
  for (int i = 0; i < (int)k; i++) hp2.insert(make_pair(dis[i], i));
  for (int i = 0; i < (int)k; i++) {
    int u = hp2.begin()->second;
    hp2.erase(hp2.begin());
    if (dis[(u + p) % k] > dis[u] + p) {
      int v = (u + p) % k;
      hp2.erase(make_pair(dis[v], v));
      dis[v] = dis[u] + p;
      hp2.insert(make_pair(dis[v], v));
    }
  }
  hp.clear();
  for (int i = 0; i < (int)n; i++) vis[i] = 0;
  for (int i = 0; i < (int)n; i++)
    if (!del[i]) {
      int p = a[i] % k;
      if (a[i] >= dis[p]) {
        vis[i] = 1;
        hp.insert(make_pair(c[i], -i));
      }
    }
}
int main() {
  scanf("%I64d%d%d%d", &h, &n, &m, &k);
  for (int i = 0; i < (int)n; i++) scanf("%I64d%d", a + i, c + i), --a[i];
  for (int i = 1; i < (int)k; i++) dis[i] = 1ll << 60;
  resolve(k);
  for (int i = 0; i < (int)m; i++) {
    scanf("%d", &ty);
    if (ty == 1) {
      scanf("%I64d", &p3);
      resolve(p3);
    } else if (ty == 2) {
      scanf("%d%d", &p1, &p2);
      --p1;
      if (vis[p1]) {
        hp.erase(make_pair(c[p1], -p1));
        c[p1] -= p2;
        hp.insert(make_pair(c[p1], -p1));
      } else
        c[p1] -= p2;
    } else if (ty == 3) {
      if (hp.empty()) {
        puts("0");
        continue;
      }
      printf("%I64d\n", hp.rbegin()->first);
      del[-hp.rbegin()->second] = 1;
      hp.erase(--hp.end());
    }
  }
}
