#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r;
  mutable long long v;
  node(int L, int R = -1, long long V = 0) : l(L), r(R), v(V) {}
  bool operator<(const node& o) const { return l < o.l; }
};
set<node> s;
inline set<node>::iterator split(int pos) {
  set<node>::iterator it = s.lower_bound(node(pos));
  if (it != s.end() && it->l == pos) return it;
  --it;
  int L = it->l, R = it->r;
  long long V = it->v;
  s.erase(it);
  s.insert(node(L, pos - 1, V));
  return s.insert(node(pos, R, V)).first;
}
inline void assign(int l, int r, int v = 0) {
  set<node>::iterator itr = split(r + 1), itl = split(l);
  s.erase(itl, itr);
  s.insert(node(l, r, v));
}
inline void add(int l, int r, int v) {
  set<node>::iterator itr = split(r + 1), itl = split(l);
  for (; itl != itr; ++itl) itl->v += v;
}
inline long long rnk(int l, int r, int k) {
  vector<pair<long long, int> > rk;
  set<node>::iterator itr = split(r + 1), itl = split(l);
  rk.clear();
  for (; itl != itr; ++itl)
    rk.push_back(make_pair(itl->v, itl->r - itl->l + 1));
  sort(rk.begin(), rk.end());
  for (vector<pair<long long, int> >::iterator i = rk.begin(); i != rk.end();
       ++i) {
    k -= i->second;
    if (k <= 0) return i->first;
  }
  return -1;
}
inline long long quickpow(long long x, long long y, long long z) {
  long long res = 1;
  x %= z;
  while (y != 0) {
    if (y & 1) res = (res * x) % z;
    x = (x * x) % z;
    y >>= 1;
  }
  return res % z;
}
inline long long sum(int l, int r, long long x, long long y) {
  set<node>::iterator itr = split(r + 1), itl = split(l);
  long long res = 0;
  for (; itl != itr; ++itl)
    res = (res + (itl->r - itl->l + 1) * quickpow(itl->v, x, y)) % y;
  return res;
}
long long rnd(long long& seed) {
  long long res = seed;
  seed = (seed * 7 + 13) % 1000000007;
  return res;
}
long long a[100001];
int main() {
  long long n, m, seed, vmax, x, y;
  cin >> n >> m >> seed >> vmax;
  for (int i = 1; i <= n; ++i) {
    a[i] = (rnd(seed) % vmax) + 1;
    s.insert(node(i, i, a[i]));
  }
  for (int i = 1; i <= m; ++i) {
    int op = (rnd(seed) % 4) + 1, l = (rnd(seed) % n) + 1,
        r = (rnd(seed) % n) + 1;
    if (l > r) swap(l, r);
    if (op == 3)
      x = (rnd(seed) % (r - l + 1)) + 1;
    else
      x = (rnd(seed) % vmax + 1);
    if (op == 4) y = (rnd(seed) % vmax) + 1;
    switch (op) {
      case 1:
        add(l, r, x);
        break;
      case 2:
        assign(l, r, x);
        break;
      case 3:
        cout << rnk(l, r, x) << endl;
        break;
      case 4:
        cout << sum(l, r, x, y) << endl;
        break;
      default:
        break;
    }
  }
}
