#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16777216")
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
long long seed;
long long a[200000];
long long rnd() {
  long long ret = seed;
  seed = (seed * 7 + 13) % 1000000007;
  return ret;
}
vector<pair<pair<int, int>, long long>> q;
int n, m, vmax;
void do1(int l, int r, long long first) {
  vector<pair<pair<int, int>, long long>> q2;
  for (int i = (0); i < (q.size()); i++) {
    pair<int, int> z =
        make_pair(max(l, q[i].first.first), min(r, q[i].first.second));
    if (z.second < z.first) {
      q2.push_back(q[i]);
      continue;
    }
    if (q[i].first.first < z.first)
      q2.push_back(
          make_pair(make_pair(q[i].first.first, z.first - 1), q[i].second));
    if (q[i].first.second > z.second)
      q2.push_back(
          make_pair(make_pair(z.second + 1, q[i].first.second), q[i].second));
    q2.push_back(make_pair(z, q[i].second + first));
  }
  q = q2;
}
void do2(int l, int r, long long first) {
  vector<pair<pair<int, int>, long long>> q2;
  q2.push_back(make_pair(make_pair(l, r), first));
  for (int i = (0); i < (q.size()); i++) {
    pair<int, int> z =
        make_pair(max(l, q[i].first.first), min(r, q[i].first.second));
    if (z.second < z.first) {
      q2.push_back(q[i]);
      continue;
    }
    if (q[i].first.first < z.first)
      q2.push_back(
          make_pair(make_pair(q[i].first.first, z.first - 1), q[i].second));
    if (q[i].first.second > z.second)
      q2.push_back(
          make_pair(make_pair(z.second + 1, q[i].first.second), q[i].second));
  }
  q = q2;
}
bool cmp(pair<pair<int, int>, long long> e1,
         pair<pair<int, int>, long long> e2) {
  return e1.second < e2.second;
}
void do3(int l, int r, long long first) {
  vector<pair<pair<int, int>, long long>> q2;
  for (int i = (0); i < (q.size()); i++) {
    pair<int, int> z =
        make_pair(max(l, q[i].first.first), min(r, q[i].first.second));
    if (z.second < z.first) continue;
    q2.push_back(make_pair(z, q[i].second));
  }
  sort(q2.begin(), q2.end(), cmp);
  for (int i = (0); i < (q2.size()); i++) {
    first -= q2[i].first.second - q2[i].first.first + 1;
    if (first <= 0) {
      cout << q2[i].second << "\n";
      return;
    }
  }
}
long long mpow(long long a, long long step, long long mod) {
  a %= mod;
  long long res = 1;
  while (step) {
    if (step & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    step >>= 1;
  }
  return res;
}
void do4(int l, int r, long long first, long long second) {
  long long res = 0;
  for (int i = (0); i < (q.size()); i++) {
    pair<int, int> z =
        make_pair(max(l, q[i].first.first), min(r, q[i].first.second));
    if (z.second < z.first) continue;
    res = (res + mpow(q[i].second, first, second) * (z.second - z.first + 1) %
                     second) %
          second;
  }
  cout << res << "\n";
}
int main() {
  cin >> n >> m >> seed >> vmax;
  for (int i = (0); i < (n); i++) {
    a[i] = rnd() % vmax + 1;
    q.push_back(make_pair(make_pair(i, i), a[i]));
  }
  for (int qw = (0); qw < (m); qw++) {
    long long op = (rnd() % 4) + 1;
    long long l = rnd() % n;
    long long r = rnd() % n;
    long long first, second = -1;
    if (l > r) swap(l, r);
    if (op == 3)
      first = rnd() % (r - l + 1) + 1;
    else
      first = (rnd() % vmax) + 1;
    if (op == 4) second = (rnd() % vmax) + 1;
    if (op == 1) do1(l, r, first);
    if (op == 2) do2(l, r, first);
    if (op == 3) do3(l, r, first);
    if (op == 4) do4(l, r, first, second);
  }
  return 0;
}
