#include <bits/stdc++.h>
using namespace std;
using LL = long long;
struct Domain {
  LL l, r;
  LL v;
  Domain(const LL &_l, const LL &_r, const LL &_v) : l(_l), r(_r), v(_v) {}
  bool operator<(const Domain &o) const { return l < o.l; }
};
ostream &operator<<(ostream &_cout, const Domain &d) {
  _cout << '[' << d.l << ' ' << d.v << ' ' << d.r << ']';
  return _cout;
}
LL N, M, seed, v;
set<Domain> domains;
vector<pair<LL, LL> > vec;
LL rnd() {
  LL ret = seed;
  seed = (seed * 7LL + 13) % 1000000007LL;
  return ret;
}
LL modPower(LL num, LL p, const LL &mod) {
  num %= mod;
  LL res = 1;
  do {
    if (p & 1) (res *= num) %= mod;
    (num *= num) %= mod;
  } while (p >>= 1);
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> M >> seed >> v;
  for (LL i = 1; i <= N; i++) {
    domains.emplace(i, i, (rnd() % v) + 1);
  }
  for (LL i = 1; i <= M; i++) {
    LL op, l, r, x, y;
    op = (rnd() % 4) + 1;
    l = (rnd() % N) + 1;
    r = (rnd() % N) + 1;
    if (l > r) swap(l, r);
    if (op == 3)
      x = (rnd() % (r - l + 1)) + 1;
    else
      x = (rnd() % v) + 1;
    if (op == 4) y = (rnd() % v) + 1;
    auto it = --domains.upper_bound(Domain(l, 0, 0));
    if (it->l < l) {
      LL tl = it->l, tr = it->r, tmp = it->v;
      domains.erase(it);
      domains.emplace(tl, l - 1, tmp);
      domains.emplace(l, tr, tmp);
    }
    it = --domains.upper_bound(Domain(r, 0, 0));
    if (it->r > r) {
      LL tl = it->l, tr = it->r, tmp = it->v;
      domains.erase(it);
      domains.emplace(tl, r, tmp);
      domains.emplace(r + 1, tr, tmp);
    }
    if (op == 1) {
      it = --domains.upper_bound(Domain(l, 0, 0));
      for (; it != domains.end() && it->r <= r; it++) {
        LL tl = it->l, tr = it->r;
        LL tmp = it->v;
        domains.erase(it);
        it = domains.emplace(tl, tr, tmp + x).first;
      }
    } else if (op == 2) {
      it = domains.lower_bound(Domain(l, 0, 0));
      for (; it != domains.end() && it->r <= r;) {
        it = domains.erase(it);
      }
      domains.emplace(l, r, x);
    } else if (op == 3) {
      vec.clear();
      it = --domains.upper_bound(Domain(l, 0, 0));
      for (; it != domains.end() && it->r <= r; it++) {
        vec.emplace_back(it->v, it->r - it->l + 1);
      }
      sort(vec.begin(), vec.end());
      LL ans;
      for (auto &item : vec) {
        if (x <= item.second) {
          ans = item.first;
          break;
        }
        x -= item.second;
      }
      cout << ans << '\n';
    } else if (op == 4) {
      auto it = --domains.upper_bound(Domain(l, 0, 0));
      LL ans = 0;
      for (; it != domains.end() && it->l <= r; it++) {
        ans +=
            ((modPower(it->v, x, y) * ((min(r, it->r) - it->l + 1)) % y)) % y;
        ans %= y;
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
