#include <bits/stdc++.h>
using namespace std;
long long n, m, h, k, d[10005], skill[10005];
int p;
bool inq[100005], vis[10005];
struct wyh {
  long long a, c;
} e[100005];
vector<int> b[10005];
priority_queue<wyh> q;
queue<int> Q;
bool cmp(int x, int y) { return e[x].a < e[y].a; }
bool operator<(wyh x, wyh y) {
  if (x.c != y.c) return x.c < y.c;
  return x.a > y.a;
}
inline long long getint() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
inline void spfa() {
  for (int i = 0; i < k; ++i)
    if (d[i] != 0x3f3f3f3f3f3f3f3fll) Q.push(i), vis[i] = 1;
  while (!Q.empty()) {
    int x = Q.front(), y;
    Q.pop();
    vis[x] = 0;
    for (int i = 1; i <= p; ++i)
      if (d[y = (x + skill[i]) % k] > d[x] + skill[i]) {
        d[y] = d[x] + skill[i];
        if (!vis[y]) Q.push(y), vis[y] = 1;
      }
  }
  for (int i = 0; i < k; ++i) {
    int num;
    while (b[i].size() && e[num = b[i][b[i].size() - 1]].a >= d[i]) {
      wyh x;
      x.a = num, x.c = e[num].c;
      q.push(x), inq[num] = 1, b[i].pop_back();
    }
  }
}
void work() {
  h = getint(), n = getint(), m = getint(), k = getint();
  skill[p = 1] = k;
  for (int i = 1; i <= n; ++i) {
    cin >> e[i].a >> e[i].c;
    b[e[i].a % k].push_back(i);
  }
  for (int i = 0; i < k; ++i) sort(b[i].begin(), b[i].end(), cmp);
  memset(d, 0x3f, sizeof(d));
  d[1] = 1;
  spfa();
  for (int i = 1; i <= m; ++i) {
    long long t, x, y;
    t = getint();
    if (t == 1) {
      skill[++p] = getint();
      spfa();
    } else if (t == 2) {
      x = getint(), y = getint();
      e[x].c -= y;
      if (inq[x]) q.push((wyh){x, e[x].c});
    } else {
      while (q.size() && q.top().c != e[q.top().a].c) q.pop();
      if (q.size())
        printf("%I64d\n", q.top().c), e[q.top().a].c = 0, q.pop();
      else
        printf("0\n");
    }
  }
}
int main() {
  work();
  return 0;
}
