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