#000044

z-procesor

Mr. Little Z has designed his first CPU, and he needs your help to test it.


The processor (CPU) has K registers, and they are all initialized to 0 - each of the registers stores a number 0. Also, each of the registers works in "mod 10000" meaning that if you load a number N into register A, then register A will actually store N mod 10000.


The processor supports the following set of instructions:


1. INC R N - The content of the register R will be increased by N, where N is an integer (0 <= N <= 5000). Hence the new content of the register R will equal to (Rold + N) MOD 10000


2. ADD R1 R2 R3 - The values from registers R1 and R2 are added and the result is stored in R3


3. MUL R1 R2 R3 - The values from registers R1 and R2 are multiplied and the result is stored in R3


4. OUT R - The content of the register R is printed to the standard output


Your task is to write a program that will simulate the processor that Mr. Little Z has designed.


InputThe input is read from the standard input. The first line will contain an integer N representing the number of registers that the processor possesses (1 <= N <= 100). The next N lines will contain the name of each register, each name consists of letters of the English alphabet and digits, the maximal length of a name will be 15 characters. After that the input will contain an integer K representing the number of instructions given to the processor (1 <= K <= 1000). Finally the next K lines contain the K instructions in the format described in the problem above

OutputTo the standard output write the processors' output - write L lines, where L is the number of OUT instructions given to the processor and each line contains an integer that is the result of the corresponding OUT instruction

Input:
2
AX
BX
6
INC AX 10
INC BX 10
MUL AX BX AX
OUT AX
ADD AX BX BX
OUT BX

Output:
100
110

The input will always contain at least 1 OUT instruction


Submit solution

Coming later

The grading service will be connected in a later migration step. You can inspect the task and your previous results now.