编程介的小学生 2017-03-12 02:57 采纳率: 20.5%
浏览 850
已采纳

XX Language

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 is a name of a variable, which consists of no more than 20 capital latin letters (i.e. 'A'..'Z'). The name of any two variables must not be identical. The name of any variable must not be "LOOP".

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) times. For example:
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 appeared in the program must be in the range 0~32767.

  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 ", a "{" or a "}". There may be arbitrary number of spaces at the beginning of the line, at the end of the line, between an operator and a variable name or a constant, or between "LOOP" and

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=3

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-03-22 14:59
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。