#Lutece0555. A+B

A+B

Migrated from Lutece 555 A+B

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

Warning\textbf{Warning}: In most Online Judges, A+B problem may be the easiest problem. However, this A+B problem is too hard for freshmen. Any naive algorithm won't pass.

Everyone knows that Lord Huang is the leader of the largest religion among the world. But few know that, before becoming the leader, he was a mathematician. He had solved many hard problems. Today, he encounters another one --- the A+B problem, which is supposed to be the most difficult problem on earth. Even Lord Huang can't solve it. Here comes the problem.

Given two numbers, AA and BB, in base PP whose lengths are both NN. Adding them up, we can get a new number CC in base PP. After changing several digits in AA or BB, their sum CC would also change. Lord Huang wants you to tell him the values of some digits in number CC.

We number the digits (00-based) from the rightmost(lowest) digit to leftmost(highest) one. For example, under base 1010, the 0th0_{th} digit of 123123 is 33, and the 2nd2_{nd} is 11.

Input

There are multiple test cases. The first line of the input will be an integer T(T20)T (T \leq 20) indicating the number of test cases.

For each test case two integers PP and N(2P10000,1N100000)N (2 \leq P \leq 10000, 1 \leq N \leq 100000) come first in a single line, representing the base and the length of AA and BB respectively.

The next two lines list the numbers AA and BB in base PP. Each line contains NN numbers, indicating digits from highest to lowest. We ensure that all these numbers are in range [0,P1][0,P-1].

The next line contains an integer M(1M100000)M (1 \leq M \leq 100000), representing the number of operations. Each operation belongs to one of the three kinds:

  • CC AA XX DD. Change the XthX_{th} digit of number AA to D(0X<N,0D<P)D (0 \leq X < N, 0 \leq D < P).
  • CC BB XX DD. Change the XthX_{th} digit of number BB to D(0X<N,0D<P)D (0 \leq X < N, 0 \leq D < P).
  • QQ XX. Output the XthX_{th} digit of number C(0X<N)C (0 \leq X < N).

Output

For each test case, print Case #k: first, in a single line, where kk indicates the case number and starts at 11.

For each "QQ XX" query, output one number in a single line, representing the XthX_{th} number in CC.

Samples

2
10 3
1 2 3
1 2 3
4
C A 0 0
Q 0
C A 0 9
Q 1
10 3
1 2 9
1 1 1
7
Q 1
C A 0 7
Q 0
Q 1
C B 1 9
Q 1
Q 2
Case #1:
3
5
Case #2:
4
8
3
1
3

Note

Huge input/output. Please use scanf/printf for C/C++.

For the first case, after operation "CC AA 00 00", AA turns into 11 22 00. And it becomes 11 22 99 after "CC AA 00 99".

Resources

10th UESTC Programming Contest Preliminary