#P7821. An Easy Matrix Problem
An Easy Matrix Problem
An Easy Matrix Problem
Problem Description
You are given an array of length and array . Denote as an array built from by \textbf{right cyclicly shifting} for elements. For example, if = and = , = , and if = and = , = . We define two matrixes and , the -th row of is and the -th row of is , . We define a matrix . This problem contains two sections. For the first section: You have to answer queries: , you should print () mod , here meaning the -th power is a parameter fixed for one test case. For the second section: You have to answer queries, and there might be types: , the -th row of . , the -th column of . , you should print () mod . Here denotes that perform . See examples for better understanding. In the example , the initial matrix :
$$\begin{bmatrix} {30}&{20}&{15}&{15}&{20}\\ {20}&{30}&{20}&{15}&{15}\\ {15}&{20}&{30}&{20}&{15}\\ {15}&{15}&{20}&{30}&{20}\\ {20}&{15}&{15}&{20}&{30}\\ \end{bmatrix}$$After the first update operation, the matrix will become:
$$\begin{bmatrix} {30}&{20}&{15}&{15}&{20}\\ {20}&{30}&{20}&{15}&{15}\\ {23}&{20}&{32}&{24}&{21}\\ {15}&{15}&{20}&{30}&{20}\\ {20}&{15}&{15}&{20}&{30}\\ \end{bmatrix}$$After the second update operation, the matrix will become:
$$\begin{bmatrix} {30}&{20}&{24}&{15}&{20}\\ {20}&{30}&{32}&{15}&{15}\\ {23}&{20}&{32}&{24}&{21}\\ {15}&{15}&{23}&{30}&{20}\\ {20}&{15}&{21}&{20}&{30}\\ \end{bmatrix}$$Input
The first line contains a single integer () denoting the number of test cases. For each test case, the first line contains single integers ,,, (,). The second line contains integers , . Each of the next lines contains integers: ( ,,, ). Each of the next lines contains or integers: , , , ( ,,,,,,, ). It is guaranteed that , , , and .
Output
For each query of type and type , output the only line containing just one integer denoting the answer.
Sample Input
1
5 3 1 5
0 4 3 2 1
0 0 0 4 4
1 2 2 1
2 2 3 2
3 1 1 3 3
3 0 0 4 1
3 0 2 4 2
Sample Output
0
1
3
2
Source
2020 Multi-University Training Contest 5