Xiao Ming is learning a new programming language, A++. Having just learned about loop statements, he excitedly wrote many programs and calculated their time complexity. However, his programming teacher does not have the time to check every single one of his programs. This is your chance! Please write a program to determine whether the time complexity provided by Xiao Ming for each of his programs is correct.
The loop structure of the A++ language is as follows:
F i x y Loop body E
Here, "F i x y" means creating a new variable $i$ (variable $i$ cannot have the same name as an existing variable that has not been destroyed) and initializing it to $x$. Then, it compares $i$ and $y$. If $i$ is less than or equal to $y$, it enters the loop; otherwise, it does not. After each loop iteration, $i$ is modified to $i+1$. Once $i$ is greater than $y$, the loop terminates.
$x$ and $y$ can be positive integers (the relationship between $x$ and $y$ is not fixed) or the variable $n$. $n$ is a variable representing the scale of the data. In time complexity calculations, this variable must be preserved and cannot be treated as a constant. $n$ is much larger than $100$.
"E" indicates the end of the loop body. When the loop body ends, the variable $i$ created for this loop is destroyed.
Note: For the sake of convenience in this problem, when describing complexity, the uppercase English letter "O" is used to represent the concept of "$\Theta$" in its usual sense.
Input
The first line contains a positive integer $t$ ($t \le 10$), representing the number of programs for which the time complexity needs to be calculated.
For each program, we only need to extract the "F i x y" and "E" lines to calculate the time complexity. Note: Nested loop structures are allowed.
The first line of each program contains a positive integer $L$ and a string. $L$ represents the number of lines in the program, and the string represents the complexity of the program. "$O(1)$" represents constant complexity, and "$O(n^w)$" represents complexity of $n^w$, where $w$ is a positive integer less than $100$ (the input does not contain the caret symbol ^). The input guarantees that the complexity is only one of the two types: $O(1)$ or $O(n^w)$.
The next $L$ lines represent the "F i x y" or "E" statements in the loop structure of the program.
If a program line starts with "F", it indicates entering a loop, followed by three space-separated characters (or strings) $i$, $x$, and $y$. $i$ is a lowercase letter (guaranteed not to be "n"), representing the name of the new variable. $x$ and $y$ can be positive integers or $n$. If they are positive integers, they are guaranteed to be less than $100$.
If a program line starts with "E", it indicates the end of the loop body.
Output
Output $t$ lines. For each of the $t$ input programs, output "Yes", "No", or "ERR" (without quotes). If the actual complexity of the program matches the complexity given in the input, output "Yes"; otherwise, output "No". If the program has a syntax error (syntax errors are limited to: ① F and E do not match, ② a new variable name conflicts with an existing variable that has not been destroyed), output "ERR".
Note: Even if a syntax error occurs in a loop body that will not be executed, it is still a compilation error and you must output "ERR".
Constraints
- For 30% of the data: There are no syntax errors, and it is guaranteed that for each program, the first $L/2$ lines are statements starting with F, and the lines from $L/2+1$ to $L$ are statements starting with E. $L \le 10$. If $x$ and $y$ are both integers, $x$ is guaranteed to be less than or equal to $y$, and only $y$ can be $n$.
- For 50% of the data: There are no syntax errors, $L \le 100$. If $x$ and $y$ are both integers, $x$ is guaranteed to be less than or equal to $y$, and only $y$ can be $n$.
- For 70% of the data: There are no syntax errors, $L \le 100$.
- For 100% of the data: $L \le 100$.
Examples
Input 1
8 2 O(1) F i 1 1 E 2 O(n^1) F x 1 n E 1 O(1) F x 1 n 4 O(n^2) F x 5 n F y 10 n E E 4 O(n^2) F x 9 n E F y 2 n E 4 O(n^1) F x 9 n F y n 4 E E 4 O(1) F y n 4 F x 9 n E E 4 O(n^2) F x 1 n F x 1 10 E E
Output 1
Yes Yes ERR Yes No Yes Yes ERR
Note 1
- The first program: $i$ goes from $1$ to $1$, constant complexity.
- The second program: $x$ goes from $1$ to $n$, $n$ to the power of $1$ complexity.
- The third program: Has an F starting a loop but no E to end it, syntax error.
- The fourth program: Double loop, $n$ squared complexity.
- The fifth program: Two single loops, $n$ to the power of $1$ complexity.
- The sixth program: The first loop is normal, but the second loop terminates immediately (because $n$ is much larger than $100$, and $100$ is greater than $4$).
- The seventh program: The first loop cannot be entered, so it is constant complexity.
- The eighth program: The variable $x$ in the second loop conflicts with the variable $x$ in the first loop, causing syntax error ②, output "ERR".
Examples 2
See the files complexity/complexity2.in and complexity/complexity2.ans in the contestant directory.