## 1197 - In Queries

Time Limit : 3 Second

Memory Limit : 128 MB

Submission: 132

Solved: 19

Description
Currenty ITComSysSC (Information Technology Computer System Student Club) needs to develop a software module which able to handle some query on data, and here they come to ask you. All the data will be integer and stored in a table of 5 columns. For the development purpose, you will use the initial data which are generated by this function:

f(r, c) = (a . f(r - 1, c) + b . f(r, c - 1) + x) mod m

f(r, c ) = 0, for all r = 0 or c = 0.

f(r, c) = the value on row r and column c, where r = 1 ... n, and c = 1 ... 5.

a, b, x, m and n are seeds for the function and will be given as input.

Here are the queries that you should handle:

QueryTo DoExample
insert a b c d eappend {a, b, c, d, e} to the last row. a = data for 1st column, b = data for 2nd column, ..., e = data for 5th column (0 <= a, b, c, d, e < m).insert 2 10 3 4 7
remove rdelete row r.remove 3
max coutput the highest value in column c.max 3
min coutput the lowest value in column c.min 1
range c a boutput the number of row which value in column c between a and b (inclusive).range 2 1 10

Each time a remove command is executed, the specified row will be deleted but all other rows below it will not be shifted (which means the row still there, only the data is emptied). If the row to be removed is already deleted/empty or out of range, then do nothing. Insert command will always append the data to the last row, even if there抮e empty rows before it (deleted rows).

You may safely assume that there's no output query (max/min/range) on empty table.

Input

The first line of input contains an integer T, the number of test cases follow.

Each case begins with five non-negative integers a, b, x, m (1 <= m <= 10,000) and n (0 <= n <= 100,000) the seed for generating the initial data. The next row contains a single integer q (0 <= q <= 100) denoting the number of queries. The next q lines each represents the query in one of the above formats.
Output
Print "Case #X:" (X is the case number) at the first line of each test case. The following lines will be the output of the test case (each output on a single line).
sample input
```3
1 1 1 5 6
9
max 5
remove 2
remove 4
min 2
insert 2 4 6 3 10
range 4 1 5
insert 0 0 0 0 0
remove 7
max 3
3 3 3 3 3
2
remove 1
insert 1 1 1 1 1
2 4 3 10 2
6
remove 1
remove 2
insert 2 2 2 2 2
remove 1
remove 10
max 3```
sample output
```Case #1:
1
0
4
4
Case #2:
Case #3:
2```
hint
source
© 2015 HUST ACMICPC TEAM. All Right Reserved.