#include <cstdio>
#include <cstdint>
#include <cassert>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

#define fprintf(...) void(0)

class Poly {
  std::map<std::string, int> coefs;
  // e.g. coefs["aab"] == 2 <=> the polynomial has the term 2 a^2 b
  const std::string s;

  Poly &operator ^=(const Poly &oth) {
    if (oth.coefs.size() == 1 && oth.coefs.find("") != oth.coefs.end()) {
      return (*this) ^= oth.coefs.find("")->second;
    } else if (oth.coefs.empty()) {
      // means 0
      coefs.clear();
      coefs[""] = 1;  // means 1
      return (*this);
    }

    assert(false);
  }

  Poly &op_eq(char op, const Poly &rhs) {
    // (*this) @= rhs
    switch (op) {
      case '+': return (*this) += rhs;
      case '-': return (*this) -= rhs;
      case '*': return (*this) *= rhs;
      case '^': return (*this) ^= rhs;
      default: assert(false);
    }
  }

  Poly fourt(
      size_t &i, 
      const std::vector<std::string> &ops={"+-", "*", "^", ""},
      size_t prec=0) {

    if (ops[prec].empty()) {
      if (s[i] == '(') {
        Poly tmp=fourt(++i, ops, 0);
        assert(s[i] == ')');
        ++i;
        return tmp;
      }
      if (isalpha(s[i])) {
        // we assume only one-character variables
        return Poly(s[i++]);
      }
      int coef=0;
      while (s[i] >= '0' && s[i] <= '9')
        coef = coef*10 + s[i++]-'0';
      return Poly(coef);
    }

    Poly res=fourt(i, ops, prec+1);
    while (i < s.length()) {
      char op=s[i];
      if (!std::count(ops[prec].begin(), ops[prec].end(), op))
        break;
      Poly tmp=fourt(++i, ops, prec+1);
      res.op_eq(op, tmp);
    }
    return res;
  }

  Poly &normalized() {
    for (auto it=coefs.begin(); it!=coefs.end(); ++it) {
      if (it->second == 0) {
        fprintf(stderr, "Removed: %s\n", it->first.c_str());
        coefs.erase(it);
      }
    }
    return *this;
  }

public:
  Poly(const std::string &s): s(s) {
    size_t i=0;
    coefs = fourt(i).coefs;  // ugh
  }

  Poly(char ch): s(1, ch) {
    assert(isalpha(ch));
    coefs[s] = 1;
  }

  Poly(int n): s(std::to_string(n)) {
    if (n)
      coefs[""] = n;
  }

  Poly &operator +=(const Poly &oth) {
    for (const auto &p: oth.coefs) {
      const std::string &param=p.first;
      int coef=p.second;
      coefs[param] += coef;
    }
    return normalized();
  }

  Poly &operator -=(const Poly &oth) {
    for (const auto &p: oth.coefs) {
      const std::string &param=p.first;
      int coef=p.second;
      coefs[param] -= coef;
    }
    return normalized();
  }

  Poly &operator *=(const Poly &oth) {
    Poly tmp(*this);
    coefs.clear();
    for (const auto &pl: tmp.coefs) {
      for (const auto &pr: oth.coefs) {
        std::string param=pl.first+pr.first;
        std::sort(param.begin(), param.end());
        coefs[param] += pl.second*pr.second;
      }
    }
    return normalized();
  }

  Poly &operator ^=(int iexp) {
    if (iexp == 0) {
      // does not appear in #1233
      coefs.clear();
      coefs[""] = 1;  // means 1
    } else {
      Poly tmp(*this);
      for (int i=1; i<iexp; ++i)
        // O(iexp) multiplications, ugh
        *this *= tmp;
    }
    return normalized();
  }

  Poly operator +(const Poly &oth) const { return Poly(*this) += oth; }
  Poly operator -(const Poly &oth) const { return Poly(*this) -= oth; }
  Poly operator *(const Poly &oth) const { return Poly(*this) *= oth; }
  Poly operator ^(int iexp) const { return Poly(*this) ^= iexp; }
  bool operator ==(const Poly &oth) const { return coefs == oth.coefs; }

  void debug() const {
    if (coefs.empty()) {
      fprintf(stderr, "#> 0\n");
      return;
    }
    fprintf(stderr, "#>");
    for (const auto &p: coefs)
      fprintf(stderr, " %d%s", p.second, p.first.c_str());
    fprintf(stderr, "\n");
  }
};

std::string normalize(const std::string &s) {
  // explicit `*' signs and no spaces
  std::string res;
  enum {
    NONE, PAREN, FACTOR, OPERATOR
  } last=NONE;
  for (size_t i=0; i<s.length(); ++i) {
    if (s[i] == '(') {
      if (last == FACTOR) {
        res += '*';
      }
      res += '(';
      last = PAREN;
    } else if (s[i] == ')') {
      res += ')';
      last = FACTOR;
    } else if (isalnum(s[i])) {
      if (last == FACTOR) {
        res += '*';
      }
      res += s[i];
      if (isdigit(s[i])) {
        while (i+1 < s.length() && isdigit(s[i+1]))
          res += s[++i];
      }
      last = FACTOR;
    } else if (!isspace(s[i])) {
      res += s[i];
      last = OPERATOR;
    }
  }
  fprintf(stderr, "#< %s\n", res.c_str());
  return res;
}

int testcase_ends() {
  char buf[96];
  fgets(buf, sizeof buf, stdin);
  std::string s=buf;
  if (s == ".\n")
    return 1;

  s = normalize(s);
  Poly ps(s);
  ps.debug();
  while (true) {
    fgets(buf, sizeof buf, stdin);
    std::string t=buf;
    if (t == ".\n") {
      printf(".\n");
      return 0;
    }

    t = normalize(t);
    Poly pt(t);
    pt.debug();
    printf("%s\n", (ps == pt)? "yes":"no");
  }
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 3112