Dynamic Declaration Language (DDL)

No attempts yetTime limit1sMemory limit128 MB

Problem

DDL is a very simple programming language in which variables are declared dynamically at run time. Every variable in DDL is a signed integer in the range 9999-9999 to 99999999. A DDL program contains up to five kinds of statements. Each statement occupies its own program line, and the first statement is on line 1.

  1. Dcl <id>
    • Dcl is the keyword for a declaration statement. id is a single (case-sensitive) letter naming a DDL variable. For example, when Dcl x executes correctly, it allocates memory for variable x and sets its value to zero.
  2. <id> = <ic>
    • An assignment statement, where id is a DDL variable and ic is a literal integer constant in the range 00 to 99999999. For example, when x = 2000 executes correctly, it changes the value of x to 2000. There may be one or more blank characters around =, but no tab characters.
  3. Goto <label> or Goto <id> <label>
    • Goto is the keyword for an unconditional or conditional jump. label is a program line number. For example, Goto 5 transfers execution to line 5. When Goto x 5 executes correctly, it transfers the flow to line 5 if and only if x>0x > 0, and to the next line otherwise. label is guaranteed to be within the range of the program's line numbers.
  4. Inc <id> or Dec <id>
    • Inc and Dec are the keywords for increment and decrement. For example, when Inc x executes correctly it adds 1 to the value of x, and Dec y subtracts 1 from the value of y.
  5. End
    • End is the keyword for the end statement; executing it stops the program.

The keywords of the DDL language are case-insensitive.

Error conditions

When one of the following erroneous statements is encountered during execution, an error message appears on its own line of the output. Each error message has the form <label> <space> <error code>, where label is the line number of the erroneous statement, the space is a single blank character, and error code is a positive integer defined below.

  1. Dcl x is erroneous if x has not been referenced (used in an assignment, jump, increment, or decrement) since the last time a Dcl x statement (declaring the same variable) was executed — unless this is the first Dcl x statement being executed. In this case a repeated-declaration error message <label> 1 is generated. Execution then transfers to the statement on the next line, and any previously and correctly executed declaration of x remains valid.
  2. Any other statement that references a variable x (in an assignment, jump, increment, or decrement) is erroneous if no Dcl x has previously been executed correctly. In this case an undeclared-reference error message <label> 2 is generated, and execution continues from the next line.

Input

The first line of the input contains a single integer NN, the number of DDL programs that follow (1N201 \le N \le 20). The first line of each program contains a single integer, the number of statements in that program, which is between 11 and 100100. There are no blank lines between programs. The statements of each DDL program are given one per line, with no blank lines between them. Statements are not labeled explicitly; instead they are labeled implicitly by their line number, starting from 1 for the first statement of each program. Programs contain no syntax errors, are guaranteed to terminate, and cause no overflow or underflow during execution. On each program line, tokens (such as Goto, =, and so on) are separated by at least one blank character, and there may be leading or trailing blank characters on a line.

Output

For each input DDL program, the first line of your output is the program number, followed by the error messages the program generates, in the order they are generated, one message per line. There must be no blank lines between error messages. Programs are numbered starting from 1.