编程介的小学生 2017-06-14 08:46 采纳率: 20.5%
浏览 852
已采纳

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

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-07-09 09:58
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c