#include <bits/stdc++.h>
using namespace std;
void pr(map<string, int> a, string s = "") {
  return;
  cout << s << endl;
  for (pair<string, int> p : a) cout << p.first << " " << p.second << endl;
  cout << "end" << endl;
}
map<string, int> add(map<string, int> a, map<string, int> b, int f = 1) {
  for (pair<string, int> p1 : a) b[p1.first] += f * p1.second;
  return b;
}
map<string, int> mult(map<string, int> a, map<string, int> b) {
  map<string, int> res;
  for (pair<string, int> p1 : a)
    for (pair<string, int> p2 : b) {
      string s = p1.first + p2.first;
      sort(s.begin(), s.end());
      int num = p1.second * p2.second;
      res[s] += num;
    }
  return res;
}
map<string, int> bnf();
int pos;
string S;
void skipsp() {
  while (S[pos] == ' ') pos++;
}
int getNum() {
  int res = 0;
  while ((int)S.size() > pos && isdigit(S[pos]))
    res = res * 10 + S[pos++] - '0';
  return res;
}
int getNum2(const string &S, int &pos) {
  int res = 0;
  while ((int)S.size() > pos && 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();
    string tmp = res;
    res = "";
    for (int i = 0; i < p; i++) res += tmp, res += ' ';
  }
  return res;
}
map<string, int> BtoM(string b) {
  map<string, int> 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--;
  }
  res[val] = num;
  return res;
}
map<string, int> calc() {
  map<string, int> res;
  res[""] = 1;
  skipsp();
  while (1) {
    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
      break;
  }
  pr(res, "calc,res");
  return res;
}
map<string, int> bnf() {
  map<string, int> res = calc();
  pr(res, "start bnf");
  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 = add(res, calc(), -1);
    else if (ch == '(')
      pos++, res = mult(res, bnf()), pos++;
    else
      break;
  }
  for (auto it = res.begin(); it != res.end(); it++)
    if (it->second == 0) res.erase(it--);
  pr(res, "return bnf");
  return res;
}
int main() {
  while (1) {
    getline(cin, S);
    if (S == ".") break;
    pos = 0;
    map<string, int> ori = bnf();
    pr(ori, "ori");
    while (1) {
      getline(cin, S);
      if (S == ".") break;
      pos = 0;
      map<string, int> res = bnf();
      cout << ((ori == res) ? "yes" : "no") << endl;
      pr(res, S);
    }
    cout << "." << endl;
  }
  return 0;
}
