#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>
#include <sstream>

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
const double EPS=1e-6;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) a.rbegin(),a.rend()
#define FLL(a,b) memset((a),b,sizeof(a))
#define CLR(a) FLL(a,0)
#define declare(a,it) __typeof(a) it=(a)
#define FOR(it,a) for(declare(a.begin(),it);it!=a.end();++it)
#define FORR(it,a) for(declare(a.rbegin(),it);it!=a.rend();++it)
template<class T,class U> ostream& operator<< (ostream& o, const pair<T,U>& v){return o << "(" << v.F << ", " << v.S << ")";}
template<class T> ostream& operator<< (ostream& o, const vector<T>& v){o << "{";rep(i,SZ(v)) o << (i?", ":"") << v[i];return o << "}";}
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
int s2i(string& a){stringstream ss(a);int r;ss>>r;return r;}
int geti(){int n;scanf("%d", &n);return n;}

/*
  factor = {(expr) | var | num} (^ num)
  term = factor (term)
  expr = term (+- expr)
 */

string in;
int pos;

typedef map<string, long long> El;
void go(){
  while(pos < SZ(in) && in[pos]==' ') ++pos;
}
El expr();
El factor(){
  go();
  El ret;
  if(isdigit(in[pos])){
    ll a = 0;
    while(pos<SZ(in) && isdigit(in[pos]))
      a = a*10 + in[pos++] - '0';
    ret[""] = a;
  }else if(isalpha(in[pos])){
    string a;
    a += in[pos++];
    go();
    if(pos<SZ(in) && in[pos]=='^'){
      ++pos;
      go();
      a = string(in[pos++]-'0',a[0]);
      //cout << a << endl;
    }
    ret[a] = 1;
  }else if(in[pos]=='('){
    ++pos;
    ret = expr();
    go();
    ++pos;
  }
  
  return ret;
}

El term(){
  go();
  auto p = factor();
  go();

  while(pos < SZ(in) && in[pos] != ')' &&
        in[pos] != '+' && in[pos] != '-'){
    El np;
    for(auto i : factor())
      for(auto j : p){
        auto ns = i.first + j.first;
        sort(ns.begin(), ns.end());
        np[ns] += i.second*j.second;
      }
    p = np;
    go();
  }
  
  return p;
}

El expr(){
  go();
  auto p = term();
  go();
  while(pos < SZ(in) && (in[pos]=='+' || in[pos]=='-')){
    auto op = in[pos++];
    for(auto f : term())
      p[f.first] += op == '+' ? f.second : -f.second;
    go();
  }
  El ret;
  for(auto f : p) if(f.second) ret[f.first] = f.second;
  return ret;
}

int main(int argc, char *argv[])
{
  while(getline(cin, in) && in != "."){
    pos = 0;
    auto p = expr();
    //for(auto pp : p) cout << pp.first << " " << pp.second << endl;
    
    while(getline(cin, in) && in != "."){
      pos = 0;
      auto q = expr();
      //for(auto pp : q) cout << pp.first << " " << pp.second << endl;        
      cout << (q == p ? "yes": "no") << endl;
    }
    cout << '.' << endl;
  }
  return 0;
}