#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<string,int> P;
typedef map<string,int> M;

M add(M a,M b){
  for(P p2:b) a[p2.first] += p2.second;
  return a;
}

M Minus(M a,M b){
  for(P p2:b) a[p2.first] -= p2.second;
  return a;
}
 
M mult(M a,M b){
  M res;
  for(P p1:a)
    for(P p2:b){
      string s = p1.first + p2.first; sort(s.begin(),s.end());
      int num = p1.second * p2.second;
      res[s] += num;
    }
  return res;
}
 
M bnf();
int pos;
string S;
void skipsp(){while(S[pos] == ' ') pos++;}
 
int getNum(){
  int res = 0;
  while(isdigit(S[pos])) res = res * 10 + S[pos++]-'0';
  return res;
}
 
int getNum2(const string &S,int &pos){
  int res = 0;
  while(isdigit(S[pos])) res = res * 10 + S[pos++]-'0';
  return res;
}

string getBlock(){
  string res;
  skipsp();
  while(isdigit(S[pos]) || isalpha(S[pos])) res += S[pos++];
  skipsp();
  if(S[pos] == '^') {
    pos++;
    skipsp();
    assert(isdigit(S[pos])&&"hut");
    int p = getNum();
    for(int i=0;i<p-1;i++) res += res.back();
  }
  return res;
}
 
M BtoM(string b){
  M res;
  int num = 1;
  string val;
  for(int i=0;i<(int)b.size();i++){
    char ch = b[i];
    if(isalpha(ch)) val += ch;
    else if(isdigit(ch)) num *= getNum2(b,i),i--;
    else assert(ch == ' ' &&  "BtoM");
  }
  res[val] = num;
  return res;
}
 
M calc(){
  M res; res[""] = 1;
  while(1){
    skipsp();
    char ch = S[pos];
    if(ch == '(') pos++,res = mult(res,bnf()),pos++;
    else if(isalpha(ch) || isdigit(ch)){
      string block = getBlock();
      res = mult(res,BtoM(block));
    }
    else if(ch == '^') assert(!"^");
    else break;
  }
  return res;
}
 
M bnf(){
  M res = calc();
  while(1){
    skipsp();
    char ch = S[pos];
    if(isalpha(ch) || isdigit(ch)) res = mult(res,calc());
    else if(ch == '+')pos++,res = add(res,calc());
    else if(ch == '-')pos++,res = Minus(res,calc());
    else if(ch == '(') pos++,res = mult(res,bnf()),pos++;
    else if(ch == '^') assert(!"^");
    else break;
  }
  for(auto it=res.begin();it!=res.end();it++) if(it->second == 0) res.erase(it);
  return res;
}
 
signed main(){
  while(1){
    getline(cin,S);
    if(S == ".") break;
    pos = 0;
    M ori = bnf();
    while(1){
      getline(cin,S);
      if(S == ".") break;
      pos = 0;
      M res = bnf();
      cout<<((ori == res)? "yes":"no")<<endl;
    }
    cout<<"."<<endl;
  }
  return 0;
}