Problem: — Willem...

— What's the matter?

— It seems that there's something wrong with Seniorious...

— I'll have a look...

<image>

Seniorious is made by linking special talismans in particular order.

After over 500 years, the carillon is now in bad condition, so Willem decides to examine it thoroughly.

Seniorious has n pieces of talisman. Willem puts them in a line, the i-th of which is an integer ai.

In order to maintain it, Willem needs to perform m operations.

There are four types of operations:

  * 1 l r x: For each i such that l ≤ i ≤ r, assign ai + x to ai.
  * 2 l r x: For each i such that l ≤ i ≤ r, assign x to ai.
  * 3 l r x: Print the x-th smallest number in the index range [l, r], i.e. the element at the x-th position if all the elements ai such that l ≤ i ≤ r are taken and sorted into an array of non-decreasing integers. It's guaranteed that 1 ≤ x ≤ r - l + 1.
  * 4 l r x y: Print the sum of the x-th power of ai such that l ≤ i ≤ r, modulo y, i.e. <image>.

Input

The only line contains four integers n, m, seed, vmax (1 ≤ n, m ≤ 105, 0 ≤ seed < 109 + 7, 1 ≤ vmax ≤ 109).

The initial values and operations are generated using following pseudo code:
    
    
      
    def rnd():  
      
        ret = seed  
        seed = (seed * 7 + 13) mod 1000000007  
        return ret  
      
    for i = 1 to n:  
      
        a[i] = (rnd() mod vmax) + 1  
      
    for i = 1 to m:  
      
        op = (rnd() mod 4) + 1  
        l = (rnd() mod n) + 1  
        r = (rnd() mod n) + 1  
      
        if (l > r):   
             swap(l, r)  
      
        if (op == 3):  
            x = (rnd() mod (r - l + 1)) + 1  
        else:  
            x = (rnd() mod vmax) + 1  
      
        if (op == 4):  
            y = (rnd() mod vmax) + 1  
      
    

Here op is the type of the operation mentioned in the legend.

Output

For each operation of types 3 or 4, output a line containing the answer.

Examples

Input

10 10 7 9


Output

2
1
0
3


Input

10 10 9 9


Output

1
1
3
3

Note

In the first example, the initial array is {8, 9, 7, 2, 3, 1, 5, 6, 4, 8}.

The operations are:

  * 2 6 7 9
  * 1 3 10 8
  * 4 4 6 2 4
  * 1 4 5 8
  * 2 1 7 1
  * 4 7 9 4 4
  * 1 2 7 9
  * 4 5 8 1 1
  * 2 5 7 5
  * 4 3 10 8 5

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
namespace io {
const int __SIZE = (1 << 21) + 1;
char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1,
                                           __c, qu[55];
int __f, qr, _eof;
inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; }
inline void gc(char &x) {
  x = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                   (iS == iT ? EOF : *iS++))
                : *iS++);
}
inline void pc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
inline void pstr(const char *s) {
  int __len = strlen(s);
  for (__f = 0; __f < __len; ++__f) pc(s[__f]);
}
inline void gstr(char *s) {
  for (__c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++);
       __c < 32 || __c > 126 || __c == ' ';)
    __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                    : *iS++);
  for (; __c > 31 && __c < 127 && __c != ' ';
       ++s, __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++))
    *s = __c;
  *s = 0;
}
template <class I>
inline bool gi(I &x) {
  _eof = 0;
  for (__f = 1,
      __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                        (iS == iT ? EOF : *iS++))
                      : *iS++);
       (__c < '0' || __c > '9') && !_eof;
       __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++)) {
    if (__c == '-') __f = -1;
    _eof |= __c == EOF;
  }
  for (x = 0; __c <= '9' && __c >= '0' && !_eof;
       __c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin),
                         (iS == iT ? EOF : *iS++))
                       : *iS++))
    x = x * 10 + (__c & 15), _eof |= __c == EOF;
  x *= __f;
  return !_eof;
}
template <class I>
inline void print(I x) {
  if (!x) pc('0');
  if (x < 0) pc('-'), x = -x;
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) pc(qu[qr--]);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io::gc;
using io::gi;
using io::gstr;
using io::pc;
using io::print;
using io::pstr;
using ll = long long;
using pii = pair<ll, ll>;
ll qpow(ll b, ll e, const ll &MOD) {
  b %= MOD;
  ll ans = 1;
  while (e) {
    if (e & 1) ans = ans * b % MOD;
    b = b * b % MOD;
    e >>= 1;
  }
  return ans;
}
struct val {
  ll l;
  mutable ll r;
  mutable ll v;
  val(ll L = -1, ll R = -1, ll V = 0) : l(L), r(R), v(V) {}
  const bool operator<(const val &o) const { return l < o.l; }
};
set<val> stt;
using it = set<val>::iterator;
it split(ll l) {
  it v = stt.lower_bound(val(l));
  if (v != stt.end() && v->l == l) return v;
  --v;
  ll L = v->l, R = v->r;
  ll V = v->v;
  v->r = l - 1;
  return stt.insert(val(l, R, V)).first;
}
void assign(ll l, ll r, ll v) {
  it a = split(l), b = split(r + 1);
  stt.erase(a, b);
  stt.insert(val(l, r, v));
}
void add(ll l, ll r, ll v) {
  it a = split(l), b = split(r + 1);
  for (; a != b; ++a) a->v += v;
}
ll pws(ll l, ll r, ll k, ll MOD) {
  it a = split(l), b = split(r + 1);
  ll ans = 0;
  for (; a != b; ++a)
    ans = (ans + 1ll * (a->r - a->l + 1) * qpow(a->v, k, MOD)) % MOD;
  return ans;
}
ll kth(ll l, ll r, ll k) {
  static pair<ll, ll> ar[100005];
  ll cnt = 0;
  it a = split(l), b = split(r + 1);
  for (; a != b; ++a) {
    ar[cnt].first = a->v;
    ar[cnt].second = a->r - a->l + 1;
    cnt++;
  }
  sort(ar, ar + cnt);
  for (ll i = (0); i < (cnt); i++) {
    k -= ar[i].second;
    if (k <= 0) return ar[i].first;
  }
  return -1;
}
ll seed;
ll rnd() {
  ll ret = seed;
  seed = (seed * 7ll + 13) % 1000000007;
  return ret;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll n, m, vmax;
  gi(n), gi(m), gi(seed), gi(vmax);
  ll last = -1, lastv = -1;
  for (ll i = (1); i < ((n) + 1); i++) {
    ll v = rnd() % vmax + 1;
    if (v != lastv) {
      if (lastv != -1) stt.insert(val(last, i - 1, lastv));
      last = i;
      lastv = v;
    }
  }
  stt.insert(val(last, n, lastv));
  stt.insert(val(n + 1, n + 1, 0));
  ll op, l, r, x;
  ll cnt = 0;
  while (m--) {
    op = rnd() % 4 + 1;
    l = rnd() % n + 1;
    r = rnd() % n + 1;
    if (l > r) swap(l, r);
    if (op == 1)
      add(l, r, rnd() % vmax + 1);
    else if (op == 2)
      assign(l, r, rnd() % vmax + 1);
    else if (op == 3)
      print(kth(l, r, rnd() % (r - l + 1) + 1)), pc('\n');
    else {
      x = rnd() % vmax + 1;
      print(pws(l, r, x, (rnd() % vmax) + 1));
      pc('\n');
    }
  }
}