#include <bits/stdc++.h>
using namespace std;
long long seed, N, M, vmax;
long long A[100009];
struct opt {
  long long k, l, r, x, y;
} Do[100009];
long long rnd() {
  long long ret = seed;
  seed = (seed * 7 + 13) % 1000000007;
  return ret;
}
void init() {
  long long i;
  for (i = 1; i <= N; i++) {
    A[i] = (rnd() % vmax) + 1;
  }
  for (i = 1; i <= M; i++) {
    Do[i].k = (rnd() % 4) + 1;
    Do[i].l = (rnd() % N) + 1;
    Do[i].r = (rnd() % N) + 1;
    if (Do[i].l > Do[i].r) swap(Do[i].l, Do[i].r);
    if (Do[i].k == 3) {
      Do[i].x = (rnd() % (Do[i].r - Do[i].l + 1)) + 1;
    } else {
      Do[i].x = (rnd() % vmax) + 1;
    }
    if (Do[i].k == 4) {
      Do[i].y = (rnd() % vmax) + 1;
    }
  }
}
struct Node {
  long long l, r;
  mutable long long val;
  Node(long long L, long long R, long long v) : l(L), r(R), val(v) {}
  bool operator<(const Node& o) const { return l < o.l; }
};
set<Node> temp;
set<Node>::iterator split(long long pos) {
  set<Node>::iterator ret = temp.lower_bound(Node(pos, -1, 0));
  if (ret != temp.end() && ret->l == pos) return ret;
  --ret;
  long long L = ret->l, R = ret->r, V = ret->val;
  temp.erase(ret);
  temp.insert(Node(L, pos - 1, V));
  return temp.insert(Node(pos, R, V)).first;
}
void flat(long long L, long long R, long long V) {
  split(L);
  split(R + 1);
  auto t1 = temp.lower_bound(Node(L, 0, 0));
  auto t2 = temp.lower_bound(Node(R + 1, 0, 0));
  temp.erase(t1, t2);
  temp.insert(Node(L, R, V));
}
void add(long long L, long long R, long long V) {
  split(L);
  split(R + 1);
  auto t1 = temp.lower_bound(Node(L, 0, 0));
  auto t2 = temp.lower_bound(Node(R + 1, 0, 0));
  for (auto i = t1; i != t2; i++) {
    i->val += V;
  }
}
long long pw(long long a, long long b, long long y) {
  if (y == 1) return 0;
  if (b == 0) return 1;
  if (a == 1) return 1;
  a = a % y;
  long long te = pw(a, b / 2, y) % y;
  assert(te < 1000000009);
  if (b & 1) {
    return (((te * te) % y) * a) % y;
  } else {
    return (te * te) % y;
  }
}
long long kth(long long L, long long R, long long k) {
  vector<pair<long long, long long> > T;
  split(L);
  split(R + 1);
  auto t1 = temp.lower_bound(Node(L, 0, 0));
  auto t2 = temp.lower_bound(Node(R + 1, 0, 0));
  for (; t1 != t2; t1++) {
    T.push_back({t1->val, t1->r - t1->l + 1});
  }
  sort(T.begin(), T.end());
  for (long long i = 0; i < T.size(); i++) {
    k -= T[i].second;
    if (k <= 0) return T[i].first;
  }
}
long long sp(long long L, long long R, long long b, long long p) {
  split(L);
  split(R + 1);
  auto t1 = temp.lower_bound(Node(L, 0, 0));
  auto t2 = temp.lower_bound(Node(R + 1, 0, 0));
  long long ret = 0;
  for (auto i = t1; i != t2; i++) {
    ret += ((i->r - i->l + 1) % p * pw(i->val, b, p)) % p;
    ret %= p;
  }
  return ret;
}
int main() {
  long long i, j;
  cin >> N >> M >> seed >> vmax;
  init();
  for (i = 1; i <= N; i++) {
    temp.insert(Node(i, i, A[i]));
  }
  temp.insert(Node(N + 1, N + 1, 0));
  for (i = 1; i <= M; i++) {
    if (Do[i].k == 1) {
      add(Do[i].l, Do[i].r, Do[i].x);
    } else if (Do[i].k == 2) {
      flat(Do[i].l, Do[i].r, Do[i].x);
    } else if (Do[i].k == 3) {
      cout << kth(Do[i].l, Do[i].r, Do[i].x) << endl;
    } else {
      cout << sp(Do[i].l, Do[i].r, Do[i].x, Do[i].y) << endl;
    }
  }
}
