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 a, b, c;
int n, m;
long long int seed, vmax;
int lft[2000060], rt[2000060];
long long int val[2000060];
int sz = 0;
set<pair<int, int>> intervals;
long long int rnd() {
  long long int ret = seed;
  seed = (seed * 7ll + 13) % ((int)1e9 + 7);
  return ret;
}
void addNewInterval(int l, int r, long long int v) {
  lft[sz] = (l);
  rt[sz] = (r);
  if (v < 0) {
    cout << "N";
  }
  val[sz] = v;
  sz++;
}
void solveA(int L, int R, long long int x) {
  pair<int, int> check = {L, -1};
  auto it = upper_bound(intervals.begin(), intervals.end(), check);
  int idOld = sz;
  while (it != intervals.end() && lft[it->second] <= R) {
    int id = it->second;
    int l = lft[id];
    int r = rt[id];
    long long int oldVal = val[id];
    if (oldVal < 0) {
      cout << "N";
    }
    if (x < 0) {
      cout << "N";
    }
    it = intervals.erase(it);
    if (l < L && r <= R) {
      addNewInterval(l, L - 1, oldVal);
      addNewInterval(L, r, oldVal + x);
    } else if (l >= L && r > R) {
      addNewInterval(R + 1, r, oldVal);
      addNewInterval(l, R, oldVal + x);
    } else if (l >= L && r <= R) {
      addNewInterval(l, r, oldVal + x);
    } else {
      addNewInterval(l, L - 1, oldVal);
      addNewInterval(L, R, oldVal + x);
      addNewInterval(R + 1, r, oldVal);
    }
  }
  int idNew = sz;
  for (int i = idOld; i < idNew; i++) {
    intervals.insert(make_pair(rt[i], i));
  }
}
void solveB(int L, int R, int x) {
  pair<int, int> check = {L, -1};
  auto it = upper_bound(intervals.begin(), intervals.end(), check);
  int idOld = sz;
  while (it != intervals.end() && lft[it->second] <= R) {
    int id = it->second;
    assert(id < sz);
    int l = lft[id];
    int r = rt[id];
    long long int oldVal = val[id];
    it = intervals.erase(it);
    if (l < L && r <= R) {
      addNewInterval(l, L - 1, oldVal);
    } else if (l >= L && r > R) {
      addNewInterval(R + 1, r, oldVal);
    } else if (l >= L && r <= R) {
    } else {
      addNewInterval(l, L - 1, oldVal);
      addNewInterval(R + 1, r, oldVal);
    }
  }
  addNewInterval(L, R, x);
  int idNew = sz;
  for (int i = idOld; i < idNew; i++) {
    assert(i < sz);
    intervals.insert(make_pair(rt[i], i));
  }
}
long long int solveC(int L, int R, int x) {
  pair<int, int> check = {L, -1};
  auto it = upper_bound(intervals.begin(), intervals.end(), check);
  vector<pair<long long int, int>> pairs;
  while (it != intervals.end() && lft[it->second] <= R) {
    int id = it->second;
    int l = lft[id];
    int r = rt[id];
    long long int oldVal = val[id];
    advance(it, 1);
    assert(id < sz);
    if (l < L && r <= R) {
      pairs.push_back(make_pair(oldVal, r - L + 1));
    } else if (l >= L && r > R) {
      pairs.push_back(make_pair(oldVal, R - l + 1));
    } else if (l >= L && r <= R) {
      pairs.push_back(make_pair(oldVal, r - l + 1));
    } else {
      pairs.push_back(make_pair(oldVal, R - L + 1));
    }
  }
  sort(pairs.begin(), pairs.end());
  int done = 0;
  int idx = 0;
  while (done + pairs[idx].second < x) {
    done += pairs[idx].second;
    idx++;
  }
  return pairs[idx].first;
}
long long int mod_pow(long long int x, long long int y, long long int m) {
  long long int r = 1;
  while (y > 0) {
    if (y % 2 == 1) {
      r = (r * x) % m;
    }
    x = (x * x) % m;
    y /= 2;
  }
  return r;
}
long long int solveD(int L, int R, long long int x, int y) {
  pair<int, int> check = {L, -1};
  auto it = upper_bound(intervals.begin(), intervals.end(), check);
  int idOld = sz;
  vector<pair<int, int>> pairs;
  long long int sum = 0;
  while (it != intervals.end() && lft[it->second] <= R) {
    int id = it->second;
    int l = lft[id];
    int r = rt[id];
    long long int oldVal = val[id];
    advance(it, 1);
    assert(id < sz);
    if (l < L && r <= R) {
      sum = (sum + (long long int)(r - L + 1) * mod_pow(oldVal % y, x, y) % y) %
            y;
    } else if (l >= L && r > R) {
      sum = (sum + (long long int)(R - l + 1) * mod_pow(oldVal % y, x, y) % y) %
            y;
    } else if (l >= L && r <= R) {
      sum = (sum + (long long int)(r - l + 1) * mod_pow(oldVal % y, x, y) % y) %
            y;
    } else {
      sum = (sum + (long long int)(R - L + 1) * mod_pow(oldVal % y, x, y) % y) %
            y;
    }
  }
  return sum % y;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> seed >> vmax;
  for (int i = 0; i < n; i++) {
    int a = (rnd() % vmax) + 1;
    lft[sz] = (i);
    rt[sz] = (i);
    val[sz] = (a);
    sz++;
    intervals.insert(make_pair(i, i));
  }
  for (int i = 0; i < m; i++) {
    int op = (rnd() % 4) + 1;
    int l = (rnd() % n);
    int r = (rnd() % n);
    if (l > r) swap(l, r);
    long long int x, y;
    if (op == 3)
      x = (rnd() % (r - l + 1)) + 1;
    else
      x = (rnd() % vmax) + 1;
    if (x < 0) {
      cout << "A";
    }
    if (op == 4) y = (rnd() % vmax) + 1;
    if (op == 1)
      solveA(l, r, x);
    else if (op == 2)
      solveB(l, r, x);
    else if (op == 3)
      cout << solveC(l, r, x) << endl;
    else
      cout << solveD(l, r, x, y) << endl;
  }
  return 0;
}