문제
A fully quantified boolean 2-CNF formula is a formula in the following form: . Each is one of two quantifiers: a universal quantifier ("for all"), or an existential quantifier ("exists"); and is a conjunction (boolean AND) of clauses (boolean OR), where and are some variables (not necessarily different) with or without negation. This formula has no free variables, so it evaluates to either true or false. We can evaluate a given fully quantified formula with a simple recursive algorithm:
- If there are no quantifiers, return the remaining expression's value of
trueorfalse. - Otherwise, recursively evaluate formulas: for .
- If return ; otherwise if return .
You are given some fully quantified boolean 2-CNF formulas. Find out if they are true or not.
입력
The first line of the input contains a single integer () — the number of test cases.
The first line of a test case contains two integers and () — the number of variables and the number of clauses in . The next line contains a string with characters describing the quantifiers. If 'A' then is a universal quantifier , otherwise if 'E' then is an existential quantifier .
Next lines describe clauses in . Each line contains two integers and (; ). If then the first variable in the -th clause is . Otherwise, if then the first variable is (negation of ). The second variable in the -th clause is similarly described by .
The sum of values of for all test cases does not exceed ; the sum of values of does not exceed .
출력
For each test case output "TRUE" if the given formula is true or "FALSE" otherwise.
예제 입력 1
3
2 2
AE
1 -2
-1 2
2 2
EA
1 -2
-1 2
3 2
AEA
1 -2
-1 -3
예제 출력 1
TRUE
FALSE
FALSE
노트
The first sample corresponds to a formula . For any we can choose making it true, hence the formula is true.
The second sample changes the order of quantifiers. Now the answer is "FALSE", because for any value of we can choose and the formula becomes false.
The third formula is . If we substitute , then no assignment of can make the second clause true, so the formula is false.
코드를 제출하려면 로그인이 필요합니다.
로그인