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 JAVA):

Solution:
import java.io.*;
import java.util.*;

public class C {
    private FastScanner in;
    private PrintWriter out;

    long seed;

    int vmax;

    long[] a;
    int n;

    final long mod = 1000000007;

    long rnd() {
        long ret = seed;
        seed = (seed * 7 + 13) % mod;
        return ret;
    }

    class Block implements Comparable<Block> {
        int from, to;
        long value;

        public Block(int from, int to, long value) {
            this.from = from;
            this.to = to;
            this.value = value;
        }

        @Override
        public int compareTo(Block o) {
            return Long.compare(value, o.value);
        }

        @Override
        public String toString() {
            return "{" +
                    "" + from +
                    ", " + to +
                    "=" + value +
                    '}';
        }
    }


    Block[] blocks;
    int blockSz;

    void splitBy(int r) {
//        System.err.println("split by " + r);
        for (int i = 0; i < blockSz; i++) {
            if (blocks[i].to > r && blocks[i].from <= r) {
                for (int j = blockSz; j > i; j--) {
                    blocks[j] = blocks[j - 1];
                }
                blockSz++;
                blocks[i + 1] = new Block(r + 1, blocks[i].to, blocks[i].value);
                blocks[i].to = r;
                break;
            }
        }
    }

    void op1(int l, int r, int x) {
        for (int i = 0; i < blockSz; i++) {
            if (blocks[i].from >= l && blocks[i].to <= r) {
                blocks[i].value += x;
            }
            if (blocks[i].from > r) {
                break;
            }
        }
    }

    void op2(int l, int r, int x) {
        for (int i = 0; i < blockSz; i++) {
            if (blocks[i].from == l) {
                blocks[i].to = r;
                blocks[i].value = x;
                int j = i + 1;
                while (j != blockSz && blocks[j].from <= r) {
                    j++;
                }
                int shift = j - (i + 1);
                for (int k = j; k < blockSz; k++) {
                    blocks[k - shift] = blocks[k];
                }
                blockSz -= shift;
                break;
            }
        }
    }

    long op3(int l, int r, int x) {
        int tmpSz = 0;
        for (int i = 0; i < blockSz; i++) {
            if (blocks[i].from >= l && blocks[i].to <= r) {
                tmp[tmpSz++] = blocks[i];
            }
        }
        Arrays.sort(tmp, 0, tmpSz);
        x--;
        for (int i = 0; i < tmpSz; i++) {
            int count = tmp[i].to - tmp[i].from + 1;
            if (x < count) {
                return tmp[i].value;
            } else {
                x -= count;
            }
        }
        throw new AssertionError();
    }

    long pow(long x, int y, long mod) {
        if (y == 0) {
            return 1 % mod;
        } else if (y == 1) {
            return x % mod;
        }
        long res = 1;
        long cur = x % mod;
        for (int it = 0; it < 30; it++) {
            if (((1 << it) & y) != 0) {
                res = res * cur % mod;
            }
            cur = cur * cur % mod;
        }
        return res;
    }

    long op4(int l, int r, int x, int y) {
        long res = 0;
        for (int i = 0; i < blockSz; i++) {
            if (blocks[i].from >= l && blocks[i].to <= r) {
                res += (blocks[i].to - blocks[i].from + 1) * pow(blocks[i].value % y, x, y);
            }
        }
        res %= y;
        return res;
    }

    Block[] tmp;

    private void solve() {
        n = in.nextInt();
//        long START = System.currentTimeMillis();
        int m = in.nextInt();
        seed = in.nextLong();
        vmax = in.nextInt();
        a = new long[n];
        tmp = new Block[n];
        for (int i = 0; i < n; i++) {
            a[i] = 1 + (rnd() % vmax);
        }
        blocks = new Block[n];
        for (int i = 0; i < n; i++) {
            blocks[i] = new Block(i, i, a[i]);
        }
        blockSz = n;
        for (int i = 0; i < m; i++) {
            long op = (rnd() % 4) + 1;
            int l = (int) (rnd() % n);
            int r = (int) (rnd() % n);
            if (l > r) {
                int tmp = l;
                l = r;
                r = tmp;
            }
            long x;
            if (op == 3) {
                x = 1 + (rnd() % (r - l + 1));
            } else {
                x = 1 + (rnd() % vmax);
            }
            long y = 0;
            if (op == 4) {
                y = (rnd() % vmax) + 1;
            }
            splitBy(l - 1);
            splitBy(r);
            if (op == 1) {
                op1(l, r, (int) x);
            } else if (op == 2) {
                op2(l, r, (int) x);
            } else if (op == 3) {
                long r1 = (op3(l, r, (int) x));
                out.println(r1);
            } else {
                long r2 = (op4(l, r, (int) x, (int) y));
                out.println(r2);
            }
        }
//        System.err.println(System.currentTimeMillis() - START);
    }

    private void run() {
        try {
            in = new FastScanner(new File("C.in"));
            out = new PrintWriter(new File("C.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    private void runIO() {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    private class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new C().runIO();
    }
}