#include <bits/stdc++.h>
#pragma GCC target("avx,tune=native")
using namespace std;
int n, m, vmax;
long long seed;
int a[200013];
long long power(long long base, long long pow, long long mod) {
  if (pow == 0) return 1;
  if (pow & 1) {
    return (base * power(base, pow - 1, mod)) % mod;
  } else {
    long long temp = power(base, pow / 2, mod);
    return (temp * temp) % mod;
  }
}
int rnd() {
  int prev = (int)seed;
  seed = (seed * 7 + 13) % 1000000007LL;
  return (int)prev;
}
map<pair<int, int>, long long> tree;
void split(int pos) {
  auto it = tree.lower_bound(make_pair(pos, pos));
  if (it == tree.end() || it->first.first > pos) {
    it--;
    pair<int, int> old = it->first;
    long long value = it->second;
    tree.erase(it);
    tree[make_pair(old.first, pos)] = value;
    tree[make_pair(pos, old.second)] = value;
  }
}
int main() {
  if (fopen("FILENAME.in", "r")) {
    freopen("FILENAME.in", "r", stdin);
    freopen("FILENAME.out", "w", stdout);
  }
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> seed >> vmax;
  for (int i = 0; i < n; i++) {
    a[i] = (rnd() % vmax) + 1;
    tree[make_pair(i, i + 1)] = a[i];
  }
  for (int i = 0; i < m; i++) {
    int op = (rnd() % 4) + 1;
    int l = (rnd() % n);
    int r = (rnd() % n);
    if (l > r) swap(l, r);
    int x;
    if (op == 3) {
      x = (rnd() % (r - l + 1)) + 1;
    } else {
      x = (rnd() % vmax) + 1;
    }
    r++;
    split(l);
    split(r);
    if (op == 1) {
      for (auto it = tree.lower_bound(make_pair(l, l));
           it != tree.end() && it->first.second <= r; it++) {
        it->second += x;
        assert(it->second >= 0);
      }
    } else if (op == 2) {
      auto itStart = tree.lower_bound(make_pair(l, l));
      auto itEnd = tree.lower_bound(make_pair(r, r));
      tree.erase(itStart, itEnd);
      tree[make_pair(l, r)] = x;
    } else if (op == 3) {
      vector<pair<long long, int>> temp;
      for (auto it = tree.lower_bound(make_pair(l, l));
           it != tree.end() && it->first.second <= r; it++) {
        temp.push_back(
            make_pair(it->second, it->first.second - it->first.first));
      }
      sort(temp.begin(), temp.end());
      x--;
      int counter = 0;
      while (x >= temp[counter].second) {
        x -= temp[counter].second;
        counter++;
      }
      assert(temp[counter].first >= 0);
      cout << temp[counter].first << endl;
    } else if (op == 4) {
      int y = (rnd() % vmax) + 1;
      long long answer = 0;
      for (auto it = tree.lower_bound(make_pair(l, l));
           it != tree.end() && it->first.second <= r; it++) {
        answer += ((it->first.second - it->first.first) *
                   (power(it->second % y, x, y))) %
                  y;
        answer %= y;
      }
      if (answer < 0) answer += y;
      assert(answer >= 0);
      cout << answer << endl;
    }
  }
}
