#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, vmax, tp;
pair<long long, int> st[N];
struct Seg {
  int l, r;
  long long v;
  friend bool operator<(Seg a, Seg b) {
    return (a.l != b.l) ? (a.l < b.l) : (a.r < b.r);
  }
};
multiset<Seg> S;
long long Pow(long long x, int b, int p, long long re = 1) {
  for (x %= p; b; b >>= 1, x = x * x % p)
    if (b & 1) re = re * x % p;
  return re;
}
namespace R {
const int mod = 1e9 + 7;
int seed, ret;
int rnd() {
  ret = seed;
  seed = (seed * 7LL + 13) % mod;
  return ret;
}
}  // namespace R
void print() {
  cerr << "now print the array : " << endl;
  for (multiset<Seg>::iterator z = S.begin(); z != S.end(); ++z)
    cerr << (*z).l << ' ' << (*z).r << ' ' << (*z).v << endl;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &R::seed, &vmax);
  for (int i = 1; i <= n; ++i) S.insert((Seg){i, i, R::rnd() % vmax + 1});
  for (int op, l, r, x, y; m; --m) {
    op = (R::rnd() & 3) + 1;
    l = R::rnd() % n + 1;
    r = R::rnd() % n + 1;
    if (l > r) swap(l, r);
    if (op == 3)
      x = R::rnd() % (r - l + 1) + 1;
    else
      x = R::rnd() % vmax + 1;
    if (op == 4) y = R::rnd() % vmax + 1;
    multiset<Seg>::iterator p = --S.lower_bound((Seg){l + 1, 0, 0});
    multiset<Seg>::iterator q = --S.lower_bound((Seg){r + 1, 0, 0});
    if ((*p).l < l) S.insert((Seg){(*p).l, l - 1, (*p).v});
    if (r < (*q).r) S.insert((Seg){r + 1, (*q).r, (*q).v});
    if (op == 2) {
      for (multiset<Seg>::iterator z = p, rin; z != q;) {
        rin = z;
        ++z;
        S.erase(rin);
      }
      S.erase(q);
      S.insert((Seg){l, r, x});
      continue;
    }
    multiset<Seg>::iterator np, nq;
    if (p == q) {
      np = nq = S.insert((Seg){l, r, (*p).v});
      S.erase(p);
    } else {
      np = S.insert((Seg){l, (*p).r, (*p).v});
      nq = S.insert((Seg){(*q).l, r, (*q).v});
      S.erase(p);
      S.erase(q);
    }
    if (op == 1) {
      Seg ins;
      for (multiset<Seg>::iterator z = np, rin; z != nq;) {
        rin = z;
        ++z;
        ins = *rin;
        ins.v += x;
        S.erase(rin);
        S.insert(ins);
      }
      ins = *nq;
      ins.v += x;
      S.erase(nq);
      S.insert(ins);
    }
    if (op == 3) {
      tp = 0;
      for (multiset<Seg>::iterator z = np; z != nq; ++z)
        st[++tp] = make_pair((*z).v, (*z).r - (*z).l + 1);
      st[++tp] = make_pair((*nq).v, (*nq).r - (*nq).l + 1);
      sort(st + 1, st + 1 + tp);
      for (int i = 1; i <= tp; x -= st[i].second, ++i) {
        if (st[i].second >= x) {
          printf("%lld\n", st[i].first);
          x = 0;
          break;
        }
      }
      if (x > 0) {
        puts("I love you, love you forever.");
        return 0;
      }
    }
    if (op == 4) {
      int ans = 0;
      for (multiset<Seg>::iterator z = np; z != nq; ++z)
        ans = (ans + Pow((*z).v, x, y) * ((*z).r - (*z).l + 1)) % y;
      ans = (ans + Pow((*nq).v, x, y) * ((*nq).r - (*nq).l + 1)) % y;
      printf("%d\n", ans);
    }
  }
  return 0;
}
