Contests Virtual Contests Problems Submit Runs Status Rank List Forum

2185.   Boolean Expression
Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 105   Accepted Runs: 29    Multiple test files

Tashj studies the Discrete Mathematics this term. One day, His teacher assigns him a homework: Write a program to compare two legal boolean expression if they are logical equal. You can assume that all the expressions in input data has correct format.

Here is the explanation of the boolean expression.

a. Each boolean variable will be presented with the letters from 'A' to 'Z'.
b. The operand only contains Boolean AND, OR, and NOT.
c. For AND, the expression "A AND B" will be written as AB.
d. For OR, the expression " A OR B" will be written as A+B.
e. For NOT, the expression "NOT A" will be written as A#.
f. There may be also parentheses '(', ')' in the boolean expression.

Input

The first line is a number N followed by a blank line, the number of the test cases. For each test case, there are two lines containing a boolean expressions.

You can assume 1 ≤ N ≤ 100 and  the length of each boolean expression will not exceed 100. There is a blank line after each case and no whitespace in any expression.

Output

For each test case, output exactly one line string "The boolean expressions B1 and B2 are logically equal!" if B1 and B2 are logical equivalency.

Else output the string "The boolean expressions B1 and B2 are not logically equal!".

Where B1 and B2 are separately two expressions of each test case in the input.

Sample Input

3

AB+AC
A(B+C)

(A+C)#
A#C#

B+C
A+D



Sample Output

The boolean expressions AB+AC and A(B+C) are logically equal!
The boolean expressions (A+C)# and A#C# are logically equal!
The boolean expressions B+C and A+D are not logically equal!


Hint

There may be many parentheses and # in the expression. For example, A##### = A#, ((A))=A.

Any two of the Boolean expressions in the input are logically equal refers to their bool values are equal in any condition, which is the common sense that you learned Discrete Mathematics or other related courses.

Source: TOJ 2006 Weekly Contest 2
Submit   List    Runs   Forum   Statistics

Tianjin University Online Judge v1.3.0
Maintance:G.D.Retop. Developer: SuperHacker, G.D.Retop