Instant Complexity#1073

Instant Complexity

1 second
64 megabytes
Very easy

Analyzing the runtime complexity of algorithms is an important tool for creating efficient programs. Algorithms running in linear time are typically much faster than those requiring quadratic time for the same task. Therefore, preference should be given to linear-time algorithms.

Usually, the execution time of an algorithm is determined with respect to — the "size" of the input data. This can be, for example, the number of objects to sort, the number of points in a polygon, and so on. Since finding a formula describing the time complexity as a function of is often difficult, it would be great if this process could be automated. Unfortunately, this is not possible in general. However, in this task, you will analyze very simple programs where this can be done. Such programs are described by the following BNF grammar, where <\textbf{number}> can be any non-negative integer:

<\textbf{Program}> ::= "BEGIN" <\textbf{Statement list}> "END"

<\textbf{Statement list}> ::= <\textbf{Statement}> | <\textbf{Statement}> <\textbf{Statement list}>

<\textbf{Statement}> ::= <\textbf{LOOP statement}> | <\textbf{OP statement}>

<\textbf{LOOP statement}> ::= <\textbf{LOOP header}> <\textbf{Statement list}> "END"

<\textbf{LOOP header}> ::= "LOOP" <\textbf{number}> | "LOOP n"

<\textbf{OP statement}> ::= "OP" <\textbf{number}>

The runtime of such a program is computed as follows: an OP statement requires as many time units as the parameter specifies. A statement list inside a LOOP statement is executed as many times as its parameter indicates: by a given constant if a number, or times if is given. The runtime of a statement list is the sum of the runtimes of its components. Therefore, the total runtime depends on .

Input

The first line contains a single integer — the number of programs in the input file. This is followed by programs conforming to the grammar above. Whitespace and newlines can appear anywhere in a program, except inside the keywords BEGIN, END, LOOP, OP, or within integer numbers.

The nesting depth of LOOP operators does not exceed , the size of the input file does not exceed KB, and coefficients in the output polynomial do not exceed .

Output

For each program, first output a line with the program number. On the next line, print the runtime in terms of as a polynomial of degree at most (with like terms combined). Higher-degree terms must precede lower-degree terms, omit terms with coefficient , and do not write coefficient . The general form is "Runtime = a*n^10 + b*n^9 + ... + i*n^2 + j*n + k". If the runtime is zero, output "Runtime = 0". Output a blank line after the polynomial, except after the last test case.

Examples

Example 1

Loading
Loading