The first line contains an integer T (1≤T≤20), the number of test cases. Each test case takes two lines.
The first line of a test case contains an integer n (1≤n≤10), the number of variables in the formula. The i-th variable is written as the i-th uppercase letter of the English alphabet, so the first variable is A and the third variable is C.
The second line contains a boolean formula of at most 256 characters. A boolean formula has one of these five forms.
var, where var is a variable.
( formula1 ), where formula1 is a boolean formula.
not formula1, where formula1 is a boolean formula.
formula1 or formula2, where formula1 and formula2 are both boolean formulas.
formula1 and formula2, where formula1 and formula2 are both boolean formulas.
Blanks separate the variables from the operators. There are four operators: and, or, not, and the brackets (). The first three are written in lower case. Precedence from high to low is (), then not, then and, then or.