#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
using namespace std;
char s[100];
stack<double>S1;
stack<char>S2;
inline double Compute(char *p)
{
while(!S1.empty()) S1.pop();
while(!S2.empty()) S2.pop();
int len=strlen(p);
for(int i=0;i<len;++i)
{
if(p[i]=='(')
{
S2.push(p[i]);
}
else if(p[i]==')')
{
while(S2.top()!='(')
{
double tmp1=S1.top(); S1.pop();
double tmp2=S1.top(); S1.pop();
char c= S2.top(); S2.pop();
if(c=='+')
{
S1.push(tmp2+tmp1);
}
if(c=='-')
{
S1.push(tmp2-tmp1);
}
if(c=='*')
{
S1.push(tmp2*tmp1);
}
if(c=='/')
{
S1.push(tmp2/tmp1);
}
}
S2.pop();
}
else if(p[i]>='0'&&p[i]<='9')
S1.push(p[i]-'0');
else if(p[i]>='a'&&p[i]<='z')
S1.push(p[i]-'a');
else if(p[i]>='A'&&p[i]<='Z')
S1.push(p[i]-'A');
else if(p[i]=='+'||p[i]=='-')
{
while(!S2.empty()&&S2.top()!='(')
{
double tmp1=S1.top(); S1.pop();
double tmp2=S1.top(); S1.pop();
char c= S2.top(); S2.pop();
if(c=='+')
{
S1.push(tmp2+tmp1);
}
if(c=='-')
{
S1.push(tmp2-tmp1);
}
if(c=='*')
{
S1.push(tmp2*tmp1);
}
if(c=='/')
{
S1.push(tmp2/tmp1);
}
}
S2.push(p[i]);
}
else if(p[i]=='*'||p[i]=='/')
{
while(!S2.empty()&&S2.top()!='('&&(S2.top()=='*'||S2.top()=='/'))
{
double tmp1=S1.top(); S1.pop();
double tmp2=S1.top(); S1.pop();
char c= S2.top(); S2.pop();
if(c=='*')
{
S1.push(tmp2*tmp1);
}
if(c=='/')
{
S1.push(tmp2/tmp1);
}
}
S2.push(p[i]);
}
}
while(!S2.empty())
{
double tmp1=S1.top(); S1.pop();
double tmp2=S1.top(); S1.pop();
char c= S2.top(); S2.pop();
if(c=='+')
{
S1.push(tmp2+tmp1);
}
if(c=='-')
{
S1.push(tmp2-tmp1);
}
if(c=='*')
{
S1.push(tmp2*tmp1);
}
if(c=='/')
{
S1.push(tmp2/tmp1);
}
}
return S1.top();
}
int main()
{
int Test;
cin>>Test;
cin.get();//注意读入换行
while(Test--)
{
gets(s);
double num1=Compute(s);
gets(s);
double num2=Compute(s);
if(num1==num2) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}