XX Language
Time Limit: 10 Seconds Memory Limit: 32768 KB
XX Language is a kind of computer language in the earlier time when computer
was invented, which includes two kinds of sentences - evaluating and looping.
The format of an evaluating sentence is like following:
Here
For example:
A=3
C=A+B-7 are both valid evaluating sentences.
An evaluating sentence means to give the result of the expression on the right
side to the variable on the left.
The format of a looping sentence is like following:
LOOP
which is followed by a sentence or a group of sentences that are between two
lines "{" and "}", means to execute this sentence (or sentence
group)
LOOP 100
A=A+1
means to execute A=A+1 100 times, and
LOOP 99
{
T=A
A=B
B=T
}
means to exchange the values of A and B 99 times.
Since the computer in the earlier time was not so powerful, the programs written
in XX Language must have following constraints:
1. The number of variables appeared in one program must not exceed 20.
2. The value of each variable must be an integer in the range 0~32767. If some
value goes out of this range during the calculation, you should make it fit
into this range again by adding or subtracting some multiple of 32768.
For example:
32765+4=1
1-4=32765
3. The initial value of each variable is 0.
4. The program written should never be longer than 1,000 lines.
5. There should not be more than 255 characters in each line.
6. All the
7. The number of "LOOP"s must not exceed 100.
You are given some programs that are written in XX Language now. Your task is
to simulate their running and output the final value of each variable.
Input
The first line of the input is a single integer X (0 < X <= 10), representing
there are X programs need you to simulate, and then X blocks each represents
a program.
The first line of each block is an integer K (0 < K <= 2,000), representing
the program has K lines, then followed by K lines each of which is an evaluating
sentence, an "LOOP
There're NO breakline between two continuous test cases.
Output
For each program output the final value of each variable in lexicographic order,
making the format as following:
There're NO breakline between two continuous test cases.
Sample Input
2 4 A = 1 B = 3 LOOP 100 A = A + B 4 A = 1 B = 3 LOOP 100 A = A + B
Sample Output
A=301 B=3 A=301 B=3Submit
Source: Online Contest of Christopher's Adventure