This problem uses a system of propositional logic with only two connectives, implication and negation. Given a list of formulas assumed to be true, decide for each query formula whether it is always true.
The implication A->B is false only when A is true and B is false. In the other three cases it is true.
| A | B | A->B |
|---|---|---|
| false | false | true |
| false | true | true |
| true | false | false |
| true | true | true |
The input contains several test cases.
Each test case begins with N (0 < N < 500), the number of assumed formulas. The next N lines each contain one formula, written with the following grammar:
Statement: Variable | Negation | (Implication)
Variable: a,b,c,d,...,t
Implication: Statement->Statement
Negation: ~(Statement)
There are 20 variables, the lowercase letters a to t. A negation always carries its parentheses and is written ~(...), and an implication is always wrapped as (...->...). A formula contains no spaces. Assume that all N formulas are true.
The next line contains M (0 < M < 500), followed by M lines that each contain one query formula.
The last line of the input contains a single 0.
For each test case, print ==== on its own line first.
Then handle the M query formulas in the order given. If a formula is true under every truth assignment that makes all N assumptions true, print True on its own line. If some such assignment makes it false, print False.
If no assignment makes all N assumptions true, then all M answers are True.