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;
int n, m, seed, vmax;
long long arr[100000];
map<long long, int> mp;
int rnd() {
  int ret = seed;
  seed = (seed * 7LL + 13) % 1000000007;
  return ret;
}
template <typename T>
struct BLOCK {
  int nb, mb, mbi;
  T *arr, *upd;
  int *st, *ed;
  typedef void (*BLOCK_UP)(T &, const T &v);
  typedef void (*BLOCK_QR)(const T &u, int l, int r);
  BLOCK::BLOCK_UP upp;
  BLOCK(T *arr, int n, typename BLOCK::BLOCK_UP upp) {
    for (mb = 1, mbi = 0; mb < 256 && mb * mb < n; mb <<= 1, mbi++)
      ;
    nb = n >> mbi;
    if ((n & (mb - 1)) != 0) nb++;
    st = new int[nb];
    ed = new int[nb];
    for (int i = 0; i < nb; i++) st[i] = i << mbi, ed[i] = st[i] + mb;
    if ((n & (mb - 1)) != 0) ed[nb - 1] = st[nb - 1] + (n & (mb - 1));
    upd = new T[nb];
    memset(upd, 0, sizeof(T) * nb);
    this->arr = arr;
    this->upp = upp;
  }
  ~BLOCK() { delete[] upd, delete[] st, delete[] ed; }
  void push(int ib) {
    for (int i = st[ib], ii = ed[ib]; i < ii; i++) upp(arr[i], upd[ib]);
    upd[ib] = 0;
  }
  void update(int l, int r, typename BLOCK::BLOCK_UP upx,
              typename BLOCK::BLOCK_UP upr, const T &v) {
    int il = l >> mbi, ir = r >> mbi, irr = (r - 1) >> mbi;
    if (il == irr) {
      push(il);
      for (int i = l; i < r; i++) upx(arr[i], v);
    } else {
      if ((l & (mb - 1)) != 0) {
        push(il);
        for (int i = l, ii = ed[il]; i < ii; i++) upx(arr[i], v);
        il++;
      }
      if ((r & (mb - 1)) != 0) {
        push(ir);
        for (int i = st[ir]; i < r; i++) upx(arr[i], v);
      }
      for (int i = il, j = ir; i < j; i++) upr(upd[i], v);
    }
  }
  void query(int l, int r, typename BLOCK::BLOCK_QR qr) {
    int il = l >> mbi, ir = r >> mbi, irr = (r - 1) >> mbi;
    if (il == irr)
      qr(upd[il], l, r);
    else {
      if ((l & (mb - 1)) != 0) qr(upd[il], l, ed[il]), il++;
      if ((r & (mb - 1)) != 0) qr(upd[ir], st[ir], r);
      for (int i = il, j = ir; i < j; i++) qr(upd[i], st[i], ed[i]);
    }
  }
};
void alter_count(long long k, int i) { mp.count(k) ? mp[k] += i : mp[k] = i; }
long long power(long long x, int n, int y) {
  long long r = (n & 1) ? x : 1, rr = n == 1 ? 1 : power(x, n >> 1, y);
  return r * rr % y * rr % y;
}
void upp(long long &x, const long long &v) { v >= 0 ? x += v : x = -v; }
void upx0(long long &x, const long long &v) { x += v; }
void upr0(long long &x, const long long &v) { x >= 0 ? x += v : x = -(-x + v); }
void upx1(long long &x, const long long &v) { x = v; }
void upr1(long long &x, const long long &v) { x = -v; }
void qr(const long long &t, int l, int r) {
  if (t >= 0)
    for (int i = l; i < r; i++) alter_count(arr[i] + t, 1);
  else
    alter_count(-t, r - l);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> seed >> vmax;
  for (int i = 0; i < n; i++) arr[i] = rnd() % vmax + 1;
  BLOCK<long long> block(arr, n, upp);
  for (int iq = 0; iq < m; iq++) {
    int op = rnd() % 4;
    int l = rnd() % n, r = rnd() % n, x, y = 0;
    if (l > r) swap(l, r);
    r++;
    if (op == 2)
      x = rnd() % (r - l) + 1;
    else
      x = rnd() % vmax + 1;
    if (op == 3) y = rnd() % vmax + 1;
    if (op == 0)
      block.update(l, r, upx0, upr0, x);
    else if (op == 1)
      block.update(l, r, upx1, upr1, x);
    else if (op == 2 || op == 3) {
      mp.clear();
      block.query(l, r, qr);
      long long ans = 0;
      if (op == 2) {
        ans = -1;
        for (auto &r : mp) {
          if (r.second >= x) {
            ans = r.first;
            break;
          } else
            x -= r.second;
        }
      } else {
        for (auto &r : mp)
          ans = (ans + power(r.first % y, x, y) * r.second % y) % y;
      }
      cout << ans << endl;
    }
  }
  return 0;
}