#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chkmx(T &x, T y) {
  return x < y ? x = y, true : false;
}
template <typename T>
bool chkmn(T &x, T y) {
  return x > y ? x = y, true : false;
}
const int maxn = 1e5;
int n, m, seed, vmx, opt, l, r, x, y;
struct Node {
  int l, r;
  mutable long long x;
  inline friend bool operator<(Node a, Node b) { return a.l < b.l; }
};
set<Node> s;
inline int rnd() {
  int ret = seed;
  seed = (1ll * seed * 7 + 13) % (int)(1e9 + 7);
  return ret;
}
inline int fpw(long long a, long long b, long long mod, long long ans = 1) {
  a %= mod;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1) ans = ans * a % mod;
  return ans;
}
set<Node>::iterator split(int p) {
  set<Node>::iterator it = s.lower_bound((Node){p, 0, 0});
  if (it != s.end() && it->l == p) return it;
  it--;
  int l = it->l, r = it->r;
  long long x = it->x;
  s.erase(it), s.insert((Node){l, p - 1, x});
  return s.insert((Node){p, r, x}).first;
}
void add(int l, int r, int k) {
  set<Node>::iterator rit = split(r + 1), lit = split(l);
  for (set<Node>::iterator it = lit; it != rit; it++) it->x += k;
}
void cover(int l, int r, int k) {
  set<Node>::iterator rit = split(r + 1), lit = split(l);
  s.erase(lit, rit), s.insert((Node){l, r, k});
}
long long kth(int l, int r, int k) {
  vector<pair<long long, int> > v;
  set<Node>::iterator rit = split(r + 1), lit = split(l);
  for (set<Node>::iterator it = lit; it != rit; it++)
    v.push_back(make_pair(it->x, it->r - it->l + 1));
  sort(v.begin(), v.end());
  for (int i = (0); i <= int((int)(v.size()) - 1); i++) {
    k -= v[i].second;
    if (k <= 0) return v[i].first;
  }
}
int ksum(int l, int r, int k, int mod) {
  set<Node>::iterator rit = split(r + 1), lit = split(l);
  int ans = 0;
  for (set<Node>::iterator it = lit; it != rit; it++)
    ans = (ans + 1ll * (it->r - it->l + 1) * fpw(it->x, k, mod) % mod) % mod;
  return ans;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &seed, &vmx);
  for (int i = (1); i <= int(n); i++) s.insert((Node){i, i, rnd() % vmx + 1});
  for (int i = (1); i <= int(m); i++) {
    opt = rnd() % 4 + 1, l = rnd() % n + 1, r = rnd() % n + 1;
    if (l > r) swap(l, r);
    if (opt == 3)
      x = rnd() % (r - l + 1) + 1;
    else
      x = rnd() % vmx + 1;
    if (opt == 4) y = rnd() % vmx + 1;
    if (opt == 1)
      add(l, r, x);
    else if (opt == 2)
      cover(l, r, x);
    else if (opt == 3)
      printf("%lld\n", kth(l, r, x));
    else if (opt == 4)
      printf("%d\n", ksum(l, r, x, y));
  }
  return 0;
}
