#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r;
  long long x;
  node() {}
  node(int l_, int r_, long long x_) {
    l = l_;
    r = r_;
    x = x_;
  }
  bool operator<(const node &t) const { return l < t.l; }
} tmp[100010];
pair<long long, int> a[100010];
int n, m, seed, vmax;
set<node> st;
int rnd() {
  int ret = seed;
  seed = (seed * 7LL + 13) % 1000000007;
  return ret;
}
long long power(long long x, long long n, long long mod) {
  x %= mod;
  long long ans = 1;
  while (n) {
    if (n & 1) ans = ans * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return ans;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &seed, &vmax);
  for (int i = 1; i <= n; ++i) st.insert(node(i, i, (rnd() % vmax) + 1));
  while (m--) {
    int op = (rnd() % 4) + 1;
    int l = rnd() % n + 1, r = rnd() % n + 1, x, y;
    if (l > r) swap(l, r);
    if (op == 3)
      x = rnd() % (r - l + 1) + 1;
    else
      x = rnd() % vmax + 1;
    if (op == 4) y = rnd() % vmax + 1;
    if (op == 1) {
      auto it = st.upper_bound(node(l, l, 0));
      --it;
      int cnt = 0;
      for (; it != st.end() && it->l <= r;) {
        if (it->l < l) tmp[cnt++] = node(it->l, l - 1, it->x);
        tmp[cnt++] = node(max(it->l, l), min(r, it->r), it->x + x);
        if (r < it->r) tmp[cnt++] = node(r + 1, it->r, it->x);
        it = st.erase(it);
      }
      for (int i = 0; i < cnt; ++i) st.insert(tmp[i]);
    } else if (op == 2) {
      auto it = st.upper_bound(node(l, l, 0));
      --it;
      int cnt = 0;
      tmp[cnt++] = node(l, r, x);
      for (; it != st.end() && it->l <= r;) {
        if (it->l < l) tmp[cnt++] = node(it->l, l - 1, it->x);
        if (r < it->r) tmp[cnt++] = node(r + 1, it->r, it->x);
        it = st.erase(it);
      }
      for (int i = 0; i < cnt; ++i) st.insert(tmp[i]);
    } else if (op == 3) {
      auto it = st.upper_bound(node(l, l, 0));
      --it;
      int cnt = 0;
      for (; it != st.end() && it->l <= r; ++it) {
        a[cnt++] = make_pair(it->x, min(r, it->r) - max(it->l, l) + 1);
      }
      sort(a, a + cnt);
      int sum = 0;
      for (int i = 0; i < cnt; ++i) {
        sum += a[i].second;
        if (x <= sum) {
          printf("%lld\n", a[i].first);
          break;
        }
      }
    } else {
      auto it = st.upper_bound(node(l, l, 0));
      --it;
      long long ans = 0;
      for (; it != st.end() && it->l <= r; ++it)
        ans = (ans + 1LL * (min(r, it->r) - max(it->l, l) + 1) *
                         power(it->x, x, y) % y) %
              y;
      printf("%lld\n", ans);
    }
  }
}
