#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cctype>
using namespace std;

class State{
public:
  int a; //ツ係ツ青?
  int x[26]; //ツ各ツ陛渉青?a~z)ツつェツ可スツ湘ヲツつゥ

  State(int _a, const int _x[26]){
    a = _a;
    for(int i = 0; i < 26; i++){
      x[i] = _x[i];
    }
  }

  State operator*(const State &st)const{
    State res(a * st.a, x);
    for(int i = 0; i < 26; i++){
      res.x[i] += st.x[i];
    }
    return res;
  }

  State operator+(const State &st)const{
    return State(a + st.a, x);
  }

  State operator-(const State &st)const{
    return State(a - st.a, x);
  }

  State operator^(const int &p)const{
    State res((int)pow(a, p), x);
    for(int i = 0; i < 26; i++){
      res.x[i] *= p;
    }
    return res;
  }

  bool operator<(const State &st)const{
    if(a == st.a){
      for(int i = 0; i < 26; i++){
        if(x[i] < st.x[i]){
          return true;
        }
        if(x[i] > st.x[i]){
          return false;
        }
      }
    }
    return a < st.a;
  }

  bool operator==(const State &st)const{
    if(a != st.a) return false;
    for(int i = 0; i < 26; i++){
      if(x[i] != st.x[i]){
        return false;
      }
    }
    return true;
  }

  bool eqx(const State &st)const{
    for(int i = 0; i < 26; i++){
      if(x[i] != st.x[i]){
        return false;
      }
    }
    return true;
  }

  void show(){
    cout << a << " ";
    for(int i = 0; i < 26; i++){
      if(x[i] != 0){
        cout << (char)('a' + i) << "^" << x[i] << " ";
      }
    }
    cout<<endl;
  }
};

int idx, n;
string s;

State mkState(int a, char ch){
  int tmp[26];
  memset(tmp, 0, sizeof(tmp));
  if(ch != ' '){
    tmp[ch - 'a'] = 1;
  }
  return State(a, tmp);
}

void init(){
  string ts = "";
  int si = 0, gi = s.length() - 1;
  while(s[si] == ' ') si++;
  while(s[gi] == ' ') gi--;

  //ツづ?づィツつ?つヲツつクツ凝ウツ板陳全ツづ?湘?つキ
  for(int i = si; i <= gi; i++){
    if(s[i] != ' '){
      ts += s[i];
    }
    else{
      int j, k;
      for(j = i - 1; s[j] == ' '; j--);
      for(k = i + 1; s[k] == ' '; k++);

      if(isdigit(s[j]) && isdigit(s[k])){
        ts += "*";
      }

      i = k - 1;
    }
  }

  for(int i = ts.length() - 1; i > 0; i--){
    if(ts[i - 1] == ')' && (ts[i] == '(' || isdigit(ts[i]) || isalpha(ts[i])) ||
       ts[i] == '(' && (isdigit(ts[i - 1]) || isalpha(ts[i - 1])) ||
       isdigit(ts[i]) && isalpha(ts[i - 1]) ||
       isdigit(ts[i - 1]) && isalpha(ts[i]) ||
       isalpha(ts[i]) && isalpha(ts[i - 1])){
      ts.insert(ts.begin() + i, '*');
    }
  }

  s = ts;
  n = s.length();
}

vector<State> zeroClear(const vector<State> &v){
  vector<State> res;

  for(int i = 0; i < v.size(); i++){
    if(v[i].a != 0){
      res.push_back(v[i]);
    }
  }

  return res;
}

vector<State> solve();

void Add(vector<State> &v1, const vector<State> &v2){
  bool used[v2.size()];
  memset(used, 0, sizeof(used));

  for(int i = 0; i < v1.size(); i++){
    for(int j = 0; j < v2.size(); j++){
      if(used[j]) continue;
      if(v1[i].eqx(v2[j])){
        v1[i] = v1[i] + v2[j];
        used[j] = true;
      }
    }
  }

  for(int i = 0; i < v2.size(); i++){
    if(!used[i]){
      v1.push_back(v2[i]);
    }
  }
}

void Sub(vector<State> &v1, const vector<State> &v2){
  bool used[v2.size()];
  memset(used, 0, sizeof(used));

  for(int i = 0; i < v1.size(); i++){
    for(int j = 0; j < v2.size(); j++){
      if(used[j]) continue;
      if(v1[i].eqx(v2[j])){
        v1[i] = v1[i] - v2[j];
        used[j] = true;
      }
    }
  }

  for(int i = 0; i < v2.size(); i++){
    if(!used[i]){
      v1.push_back(State(-1 * v2[i].a, v2[i].x));
    }
  }
}

vector<State> Mul(const vector<State> &v1, const vector<State> &v2){
  vector<State> res;

  for(int i = 0; i < v1.size(); i++){
    for(int j = 0; j < v2.size(); j++){
      bool flg = false;
      State st = v1[i] * v2[j];

      for(int k = 0; k < res.size(); k++){
        if(res[k].eqx(st)){
          res[k] = res[k] + st;
          flg = true;
          break;
        }
      }

      if(!flg){
        res.push_back(st);
      }
    }
  }

  return res;
}

void Pow(vector<State> &v, const int &p){
  for(int i = 0; i < v.size(); i++){
    v[i] = v[i] ^ p;
  }
}

int digit(){
  int res = 0;

  while(idx < n && isdigit(s[idx])){
    res *= 10;
    res += s[idx] - '0';
    idx++;
  }

  return res;
}

vector<State> factor(){
  vector<State> v;

  if(s[idx] == '('){
    idx++;
    v = solve();
    idx++;
  }
  else if(isdigit(s[idx])){
    int d = digit();
    v.push_back(mkState(d, ' '));
  }
  else{
    v.push_back(mkState(1, s[idx]));
    idx++;
  }

  if(idx < n && s[idx] == '^'){
    idx++;
    int d = digit();
    Pow(v, d);
  }

  return v;
}

vector<State> term(){
  vector<State> v = factor();

  while(idx < n){
    if(s[idx] == '*'){
      idx++;
      v = Mul(v, factor());
    }
    else{
      return v;
    }
  }

  return v;
}

vector<State> solve(){
  vector<State> v = term();

  while(idx < n){
    if(s[idx] == '+'){
      idx++;
      Add(v, term());
    }
    else if(s[idx] == '-'){
      idx++;
      Sub(v, term());
    }
    else{
      return v;
    }
  }

  return v;
}

int main(){
  while(getline(cin, s), s != "."){
    init();
    idx = 0;
    vector<State> v1 = solve();
    v1 = zeroClear(v1);
    sort(v1.begin(), v1.end());

    while(getline(cin, s), s != "."){
      init();
      idx = 0;
      vector<State> v2 = solve();
      v2 = zeroClear(v2);
      sort(v2.begin(), v2.end());

      if(v1 == v2){
        cout << "yes\n";
      }
      else{
        cout << "no\n";
      }
    }

    cout << ".\n";
  }
}