시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB214419.048%

문제

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:

Query To Do Example
insert a b c d e append {a, b, c, d, e} to the last row. a = data for 1st column, b = data for 2nd column, …, e = data for 5th column. insert 2 10 3 4 7
remove r delete row r. remove 3
max c output the highest value in column c. max 3
min c output the lowest value in column c. min 1
range c a b output 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’re empty rows before it (deleted rows).

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

입력

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.

출력

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).

예제 입력 1

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

예제 출력 1

Case #1:
1
0
4
4
Case #2:
Case #3:
2