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;
long long seed, N, M, vmax;
long long A[100009];
struct opt {
  long long k, l, r, x, y;
} Do[100009];
long long rnd() {
  long long ret = seed;
  seed = (seed * 7 + 13) % 1000000007;
  return ret;
}
void init() {
  long long i;
  for (i = 1; i <= N; i++) {
    A[i] = (rnd() % vmax) + 1;
  }
  for (i = 1; i <= M; i++) {
    Do[i].k = (rnd() % 4) + 1;
    Do[i].l = (rnd() % N) + 1;
    Do[i].r = (rnd() % N) + 1;
    if (Do[i].l > Do[i].r) swap(Do[i].l, Do[i].r);
    if (Do[i].k == 3) {
      Do[i].x = (rnd() % (Do[i].r - Do[i].l + 1)) + 1;
    } else {
      Do[i].x = (rnd() % vmax) + 1;
    }
    if (Do[i].k == 4) {
      Do[i].y = (rnd() % vmax) + 1;
    }
  }
}
struct Node {
  long long l, r;
  mutable long long val;
  Node(long long L, long long R, long long v) : l(L), r(R), val(v) {}
  bool operator<(const Node& o) const { return l < o.l; }
};
set<Node> temp;
set<Node>::iterator split(long long pos) {
  set<Node>::iterator ret = temp.lower_bound(Node(pos, -1, 0));
  if (ret != temp.end() && ret->l == pos) return ret;
  --ret;
  long long L = ret->l, R = ret->r, V = ret->val;
  temp.erase(ret);
  temp.insert(Node(L, pos - 1, V));
  return temp.insert(Node(pos, R, V)).first;
}
void flat(long long L, long long R, long long V) {
  split(L);
  split(R + 1);
  auto t1 = temp.lower_bound(Node(L, 0, 0));
  auto t2 = temp.lower_bound(Node(R + 1, 0, 0));
  temp.erase(t1, t2);
  temp.insert(Node(L, R, V));
}
void add(long long L, long long R, long long V) {
  split(L);
  split(R + 1);
  auto t1 = temp.lower_bound(Node(L, 0, 0));
  auto t2 = temp.lower_bound(Node(R + 1, 0, 0));
  for (auto i = t1; i != t2; i++) {
    i->val += V;
  }
}
long long pw(long long a, long long b, long long y) {
  if (y == 1) return 0;
  if (b == 0) return 1;
  if (a == 1) return 1;
  a = a % y;
  long long te = pw(a, b / 2, y) % y;
  assert(te < 1000000009);
  if (b & 1) {
    return (((te * te) % y) * a) % y;
  } else {
    return (te * te) % y;
  }
}
long long kth(long long L, long long R, long long k) {
  vector<pair<long long, long long> > T;
  split(L);
  split(R + 1);
  auto t1 = temp.lower_bound(Node(L, 0, 0));
  auto t2 = temp.lower_bound(Node(R + 1, 0, 0));
  for (; t1 != t2; t1++) {
    T.push_back({t1->val, t1->r - t1->l + 1});
  }
  sort(T.begin(), T.end());
  for (long long i = 0; i < T.size(); i++) {
    k -= T[i].second;
    if (k <= 0) return T[i].first;
  }
}
long long sp(long long L, long long R, long long b, long long p) {
  split(L);
  split(R + 1);
  auto t1 = temp.lower_bound(Node(L, 0, 0));
  auto t2 = temp.lower_bound(Node(R + 1, 0, 0));
  long long ret = 0;
  for (auto i = t1; i != t2; i++) {
    ret += ((i->r - i->l + 1) % p * pw(i->val, b, p)) % p;
    ret %= p;
  }
  return ret;
}
int main() {
  long long i, j;
  cin >> N >> M >> seed >> vmax;
  init();
  for (i = 1; i <= N; i++) {
    temp.insert(Node(i, i, A[i]));
  }
  temp.insert(Node(N + 1, N + 1, 0));
  for (i = 1; i <= M; i++) {
    if (Do[i].k == 1) {
      add(Do[i].l, Do[i].r, Do[i].x);
    } else if (Do[i].k == 2) {
      flat(Do[i].l, Do[i].r, Do[i].x);
    } else if (Do[i].k == 3) {
      cout << kth(Do[i].l, Do[i].r, Do[i].x) << endl;
    } else {
      cout << sp(Do[i].l, Do[i].r, Do[i].x, Do[i].y) << endl;
    }
  }
}