C – Buddy Functions

 

Problem

 

A buddy function on variable x is an expression constructed according to the following grammar:

 

E ::= ( E ) | E + E | E E | E * E | x | num

 

Here num represents an integer. Two buddy functions are equivalent if they yield the same result for all values of the argument x. Write a program that given two buddy functions determines if they are equivalent. The operators have the usual arithmetical meaning.

 

Input

The input of your program consists of a single line containing an integer N, followed by a sequence of N pairs of text lines. Each such line contains a buddy function with up to 120 non-blank characters of length. 

 

Output

The output of your program consists a sequence of N text lines. Each line contains either the character Y (if the buddy functions in the ith pair are equivalent) or N (if the buddy functions in the ith pair are not equivalent).

 

Sample Input

2

(4+x)*(4-x)

16-x*x

x*x*x*x

x*x+x*x

 

Sample Output

Y

N