#P7810. Funny String

Funny String

Funny String

Problem Description

You are given a string SS with length nn. And it is guaranteed that SiS_i \in [1,m][1,m] for ii from 11 to nn. Denote suf(S,i)suf(S,i) as the suffix of SS with length ni+1n-i+1. In other words,suf(S,i)=SiSi+1...Snsuf(S,i)=S_iS_{i+1}...S_n. Each time you will be asked one of the following questions: 1.Given a character cc and an integer ii. Then you will obtain a new string TT by inserting the character cc to the front of SS (namely T=cS1S2...SnT=cS_1S_2...S_n ). What is the rank of suf(T,i)suf(T,i) among all the suf(T,k)suf(T,k) (k[1,n+1]k\in[1,n+1]) in lexicographical order. 2.Given a character cc and an integer ii. Then you will obtain a new string TT by inserting the character cc to the back of SS (namely T=S1S2...SncT=S_1S_2...S_nc ). What is the rank of suf(T,i)suf(T,i) among all the suf(T,k)suf(T,k) (k[1,n+1]k\in[1,n+1]) in lexicographical order. Notice, we just want to find the answer of each question and won't really add the character cc to the string SS. In other words, each question is independent .

Input

The first line contains a single integer T(1T30)T(1 \leq T \leq 30) , the number of test cases. For each test case, the first line gives three integers nn, mm and qq (1n,m,q1061 \leq n,m,q \leq 10^6). nn is the length of string SS, each character SiS_i \in [1,m][1,m] and qq is the number of questions. The next line gives the string SS that consists of nn positive integers which are in [1,m][1,m]. Each of the following qq lines consists of three integers $t,c,i(1 \leq t \leq 2,1 \leq c \leq m,1 \leq i \leq n+1)$, representing the type of this question is 11 if t=1t=1 and 22 if t=2t=2. Note that cc and ii is encrypted. Assuming lastlast is the previous query answer, the actual values of cc and ii are clastc \oplus last and ilasti \oplus last (\oplus denotes the exclusive or operation). For the first query , last=0last = 0. It is guaranteed that both \sum nn and \sum qq don't exceed 3×1063 \times 10^6.

Output

For each test case, you should print qq lines, each containing an integer, indicating the query answer.

Sample Input

1
8 50 5
10 20 30 10 20 30 10 20
2 40 5
2 45 1
2 42 1
1 2 15
1 13 4

Sample Output

5
2
7
2
6

Source

2020 Multi-University Training Contest 5