#P7810. Funny String
Funny String
Funny String
Problem Description
You are given a string with length . And it is guaranteed that for from to . Denote as the suffix of with length . In other words,. Each time you will be asked one of the following questions: 1.Given a character and an integer . Then you will obtain a new string by inserting the character to the front of (namely ). What is the rank of among all the () in lexicographical order. 2.Given a character and an integer . Then you will obtain a new string by inserting the character to the back of (namely ). What is the rank of among all the () in lexicographical order. Notice, we just want to find the answer of each question and won't really add the character to the string . In other words, each question is independent .
Input
The first line contains a single integer , the number of test cases. For each test case, the first line gives three integers , and (). is the length of string , each character and is the number of questions. The next line gives the string that consists of positive integers which are in . Each of the following 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 if and if . Note that and is encrypted. Assuming is the previous query answer, the actual values of and are and ( denotes the exclusive or operation). For the first query , . It is guaranteed that both and don't exceed .
Output
For each test case, you should print 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