#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
: 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, and , in base whose lengths are both . Adding them up, we can get a new number in base . After changing several digits in or , their sum would also change. Lord Huang wants you to tell him the values of some digits in number .
We number the digits (-based) from the rightmost(lowest) digit to leftmost(highest) one. For example, under base , the digit of is , and the is .
Input
There are multiple test cases. The first line of the input will be an integer indicating the number of test cases.
For each test case two integers and come first in a single line, representing the base and the length of and respectively.
The next two lines list the numbers and in base . Each line contains numbers, indicating digits from highest to lowest. We ensure that all these numbers are in range .
The next line contains an integer , representing the number of operations. Each operation belongs to one of the three kinds:
- . Change the digit of number to .
- . Change the digit of number to .
- . Output the digit of number .
Output
For each test case, print Case #k:
first, in a single line, where indicates the case number and starts at .
For each " " query, output one number in a single line, representing the number in .
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 " ", turns into . And it becomes after " ".
Resources
10th UESTC Programming Contest Preliminary