#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<stack>
#include<cstring>
#include<set>
#include<iterator>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<cmath>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define lowbit(x) x&(-x)
typedef long long ll;
typedef pair<int, int> P;
const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
#define IT set<node>::iterator
struct node
{
int l, r;
mutable ll v;
node(int l, int r = -1, ll v = 0) :l(l), r(r), v(v) {}
bool operator <(const node &o)const
{
return l < o.l;
}
};
set<node> s;
ll power(ll a, ll b, ll mod)
{
ll ans = 1 % mod;
for (; b; b >>= 1)
{
if (b&1)
ans = ans * a%mod;
a = a % mod * a%mod;
}
return ans;
}
IT split(int pos)
{
IT it = s.lower_bound(node(pos));
if (it != s.end() && it->l == pos)
return it;
--it;
int l = it->l, r = it->r;
ll v = it->v;
s.erase(it);
s.insert(node(l, pos - 1, v));
return s.insert(node(pos, r, v)).first;
}
void add(int l, int r, ll val)
{
IT itr = split(r + 1), itl = split(l);
for (; itl != itr; itl++)
{
itl->v += val;
}
}
void assign_val(int l, int r, ll val)
{
IT itr = split(r + 1), itl = split(l);
s.erase(itl, itr);
s.insert(node(l, r, val));
}
ll ranks(int l, int r, int k)
{
vector<pair<ll, int>> v;
IT itr = split(r + 1), itl = split(l);
for (; itl != itr; itl++)
v.push_back(pair<ll, int>(itl->v, itl->r - itl->l + 1));
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); i++)
{
k -= v[i].second;
if (k <= 0)
return v[i].first;
}
}
ll sum(int l, int r, int ex, int mod)
{
IT itr = split(r + 1), itl = split(l);
ll res = 0;
for (; itl != itr; itl++)
{
res = (res + (itl->r - itl->l + 1)*power(itl->v, ex, mod)) % mod;
}
return res;
}
ll seed, vmax;
int n, m;
ll rnd()
{
ll ret = seed;
seed = (seed * 7 + 13) % mod;
return ret;
}
ll a[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m >> seed >> vmax;
for (int i = 1; i <= n; i++)
{
a[i] = (rnd() % vmax) + 1;
s.insert(node(i, i, a[i]));
}
s.insert(node(n + 1, n + 1, 0));
int op, l, r, x, y = 0;
for (int i = 1; i <= m; i++)
{
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() % vmax) + 1;
if (op == 4)
y = (rnd() % vmax) + 1;
if (op == 1)
add(l, r, x);
else if (op == 2)
assign_val(l, r, x);
else if (op == 3)
cout << ranks(l, r, x) << endl;
else
cout << sum(l, r, x, y) << endl;
}
return 0;
}