#include <bits/stdc++.h>
using namespace std;
string pre_processing(string &in);
class Element {
 public:
  int c;
  int p[27];
  Element() {
    c = 0;
    for (int i = 0; i < 27; i++) p[i] = 0;
  }
};
Element ori;
bool is_same_Element(Element a, Element b) {
  for (int i = 0; i < 27; i++)
    if (a.p[i] != b.p[i]) return false;
  return true;
}
bool is_same_formula(vector<Element> a, vector<Element> b) {
  for (int i = 0; i < a.size(); i++) {
    bool canfind = false;
    if (a[i].c == 0) continue;
    for (int j = 0; j < b.size(); j++) {
      if (is_same_Element(a[i], b[j]) && a[i].c == b[j].c) {
        b.erase(b.begin() + j);
        canfind = true;
        break;
      }
    }
    if (!canfind) return false;
  }
  return true;
}
void erase_duplicate(vector<Element> &ret) {
  for (int i = 0; i < ret.size(); i++) {
    for (int j = i + 1; j < ret.size(); j++) {
      if (is_same_Element(ret[i], ret[j])) {
        ret[i].c += ret[j].c;
        ret.erase(ret.begin() + j);
        j--;
      }
    }
  }
  for (int i = 0; i < ret.size(); i++) {
    if (ret[i].c == 0) {
      ret.erase(ret.begin() + i);
      i--;
    }
  }
  if (ret.size() == 0) ret.push_back(ori);
}
vector<Element> mult(vector<Element> a, vector<Element> b) {
  vector<Element> ret;
  for (int i = 0; i < a.size(); i++) {
    if (a[i].c == 0) continue;
    for (int j = 0; j < b.size(); j++) {
      if (b[j].c == 0) continue;
      Element tmp;
      tmp.c = a[i].c * b[j].c;
      for (int k = 0; k < 27; k++) {
        tmp.p[k] = a[i].p[k] + b[j].p[k];
      }
      ret.push_back(tmp);
    }
  }
  erase_duplicate(ret);
  return ret;
}
vector<Element> plu(vector<Element> a, vector<Element> b) {
  vector<Element> ret;
  for (int i = 0; i < a.size(); i++)
    if (a[i].c != 0) ret.push_back(a[i]);
  for (int i = 0; i < b.size(); i++)
    if (b[i].c != 0) ret.push_back(b[i]);
  erase_duplicate(ret);
  return ret;
}
vector<Element> minu(vector<Element> a, vector<Element> b) {
  vector<Element> ret;
  for (int i = 0; i < a.size(); i++)
    if (a[i].c != 0) ret.push_back(a[i]);
  for (int i = 0; i < b.size(); i++) {
    if (b[i].c != 0) {
      Element tmp = b[i];
      tmp.c *= -1;
      ret.push_back(tmp);
    }
  }
  erase_duplicate(ret);
  return ret;
}
void output(vector<Element> a) {
  cout << "output begin" << endl;
  for (int i = 0; i < a.size(); i++) {
    cout << a[i].c;
    for (int j = 0; j < 27; j++) {
      if (a[i].p[j] == 0) continue;
      cout << (char)(j + 'a') << "^" << a[i].p[j];
    }
    cout << endl;
  }
  cout << "output end" << endl;
}
vector<Element> term(string &in, int &p);
vector<Element> fact(string &in, int &p);
vector<Element> digit(string &in, int &p);
int num(string &in, int &p);
vector<Element> fact(string &in, int &p) {
  vector<Element> ret = term(in, p);
  while (p < in.size()) {
    if (in[p] == '+') {
      p++;
      vector<Element> tmp = term(in, p);
      ret = plu(ret, tmp);
    } else if (in[p] == '-') {
      p++;
      vector<Element> tmp = term(in, p);
      ret = minu(ret, tmp);
    } else
      break;
  }
  return ret;
}
vector<Element> term(string &in, int &p) {
  vector<Element> ret = digit(in, p);
  while (p < in.size()) {
    if (in[p] == '*') {
      p++;
      vector<Element> tmp = digit(in, p);
      ret = mult(ret, tmp);
    } else if (in[p] == '+' || in[p] == '-')
      break;
    else if (in[p] == '(' || isdigit(in[p]) || isalpha(in[p])) {
      vector<Element> tmp = digit(in, p);
      ret = mult(ret, tmp);
    } else if (in[p] == ')')
      break;
  }
  return ret;
}
vector<Element> digit(string &in, int &p) {
  vector<Element> ret;
  if (in[p] == '(') {
    p++;
    ret = fact(in, p);
    p++;
  } else if (isdigit(in[p])) {
    int tmp = num(in, p);
    Element ins;
    ins.c = tmp;
    ret.push_back(ins);
  } else if (isalpha(in[p])) {
    Element tmp;
    tmp.c = 1;
    while (p < in.size() && isalpha(in[p])) {
      tmp.p[in[p] - 'a']++;
      p++;
    }
    ret.push_back(tmp);
  }
  if (p < in.size() && in[p] == '^') {
    vector<Element> ori = ret;
    p++;
    int power = num(in, p);
    Element tmp;
    tmp.c = 1;
    ret.clear();
    ret.push_back(tmp);
    for (int i = 0; i < power; i++) {
      ret = mult(ret, ori);
    }
  }
  return ret;
}
int num(string &in, int &p) {
  int tmp = 0;
  while (p < in.size() && isdigit(in[p])) {
    tmp = (tmp * 10) + (in[p] - '0');
    p++;
  }
  return tmp;
}
int main() {
  string in;
  while (getline(cin, in) && in != ".") {
    in = pre_processing(in);
    int p = 0;
    vector<Element> me = fact(in, p);
    string cmp;
    while (getline(cin, cmp) && cmp != ".") {
      cmp = pre_processing(cmp);
      p = 0;
      vector<Element> you = fact(cmp, p);
      if (is_same_formula(me, you))
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
    cout << "." << endl;
  }
  return false;
}
string pre_processing(string &in) {
  bool last = false;
  int prev = -2;
  string ret = "";
  for (int i = 0; i < in.size(); i++) {
    if (in[i] == ' ') continue;
    if (isdigit(in[i]) || isalpha(in[i])) {
      if (i != 0 && in[i - 1] == ' ' && last == true) ret += '*';
      last = true;
    } else
      last = false;
    ret += in[i];
  }
  return ret;
}
void test() {
  Element a, b, c;
  a.c = 2;
  a.p[0] = 1;
  a.p[1] = 2;
  b.c = 1;
  b.p[0] = 1;
  b.p[1] = 3;
  b.p[2] = 3;
  c.c = 1;
  c.p[0] = 1;
  c.p[2] = 1;
  vector<Element> A, B, C;
  A.push_back(a);
  A.push_back(b);
  B.push_back(c);
  cout << "A" << endl;
  output(A);
  cout << "B" << endl;
  output(B);
  cout << "C" << endl;
  output(C);
  vector<Element> Mtest = minu(A, A);
  cout << "test" << endl;
  output(Mtest);
}
