#P7821. An Easy Matrix Problem

An Easy Matrix Problem

An Easy Matrix Problem

Problem Description

You are given an array b[0..n1]b[0..n-1] of length nn and array ai=i,i[0,n1]a_i = i, i \in [0,n-1]. Denote Shift(p,i)Shift(p,i) as an array built from pp by \textbf{right cyclicly shifting} for ii elements. For example, if nn = 33 and pp = aa, Shift(p,1)Shift(p,1) = 2,0,12,0,1, and if nn = 55 and pp = aa, Shift(p,3)Shift(p,3) = 2,3,4,0,12,3,4,0,1. We define two n×nn \times n matrixes AA and BB, the ii-th row of AA is Shift(a,i)Shift(a,i) and the ii-th row of BB is Shift(b,i)Shift(b,i), i[0,n1]\forall i \in [0,n-1]. We define a n×nn\times n matrix C=A×BC = A\times B. This problem contains two sections. For the first section: You have to answer mm queries: 00 pxp_x pyp_y qxq_x qyq_y, you should print (i=pxqxj=pyqyCi,jt\sum_{i=p_x}^{q_x}\sum_{j=p_y}^{q_y}C_{i,j}^t) mod nn, here tt meaning the tt-th power is a parameter fixed for one test case. For the second section: You have to answer qq queries, and there might be 33 types: 11 ii kk vv, the ii-th row of CC +=k×Shift(a,v)+=k \times Shift(a,v). 22 jj kk vv, the jj-th column of CC +=k×Shift(a,v)+=k \times Shift(a,v). 33 pxp_x pyp_y qxq_x qyq_y, you should print (i=pxqxj=pyqyCi,j\sum_{i=p_x}^{q_x}\sum_{j=p_y}^{q_y}C_{i,j}) mod nn. Here a+=ba+=b denotes that perform ai=ai+bi,i[0,n1]a_i=a_i+b_i, \forall i \in [0,n-1]. See examples for better understanding. In the example , the initial matrix CC:

$$\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 CC 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 CC 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 TT (1T30001\leq T \leq 3000) denoting the number of test cases. For each test case, the first line contains 44 single integers nn,tt,mm,qq (1n,m,q1051\leq n,m,q \leq 10^{5},1t10181\leq t \leq 10^{18}). The second line contains nn integers bib_i, i[0,n1]i \in [0,n-1]. Each of the next mm lines contains 55 integers: 00 pxp_x pyp_y qxq_x qyq_y(00\leq pxp_x,pyp_y,qxq_x,qyq_y n1\leq n-1). Each of the next qq lines contains 44 or 55 integers: 11 ii kk vv, 22 jj kk vv, 33 pxp_x pyp_y qxq_x qyq_y, (00\leq pxp_x,pyp_y,qxq_x,qyq_y,kk,vv,ii,jj n1\leq n-1). It is guaranteed that n5×105\sum n \le 5 \times 10^5, m5×105\sum m \le 5 \times 10^5, q5×105\sum q \le 5 \times 10^5, and pxqx,pyqyp_x \le q_x,p_y \le q_y.

Output

For each query of type 00 and type 33, 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