#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
string s;
vi operator+(const vi& x, const vi& y) {
  vi z;
  for (int i = 0; i < (int)(26); i++) z.push_back(x[i] + y[i]);
  return z;
}
map<vi, int> pro(map<vi, int> a, map<vi, int> b) {
  map<vi, int> c;
  for (auto p : a)
    for (auto q : b) {
      c[p.first + q.first] += p.second * q.second;
    }
  return c;
}
map<vi, int> expr(int& it);
int dig(int& it) {
  int x = 0;
  while (isdigit(s[it])) {
    x *= 10;
    x += s[it] - '0';
    it++;
  }
  return x;
}
map<vi, int> fac(int& it) {
  if (s[it] == ' ') it++;
  if (s[it] == '(') {
    it++;
    map<vi, int> ret = expr(it);
    assert(s[it] == ')');
    it++;
    return ret;
  } else if (islower(s[it])) {
    int c = s[it] - 'a';
    int o = 1;
    if (s[it + 1] == '^') {
      o = s[it + 2] - '0';
      it += 2;
    }
    it++;
    map<vi, int> ret;
    vi a(26, 0);
    a[c] = o;
    ret[a] = 1;
    return ret;
  } else {
    assert(isdigit(s[it]));
    int x = dig(it);
    map<vi, int> ret;
    vi a(26, 0);
    ret[a] = x;
    return ret;
  }
}
map<vi, int> term(int& it) {
  map<vi, int> ret = fac(it);
  while (it < s.size() && s[it] != '+' && s[it] != '-' && s[it] != ')') {
    map<vi, int> a = fac(it);
    ret = pro(ret, a);
  }
  return ret;
}
map<vi, int> expr(int& it) {
  map<vi, int> ret = term(it);
  while (s[it] == '+' || s[it] == '-') {
    if (s[it] == '+') {
      it++;
      map<vi, int> a = term(it);
      for (auto p : a) ret[p.first] += p.second;
    } else {
      it++;
      map<vi, int> a = term(it);
      for (auto p : a) ret[p.first] -= p.second;
    }
  }
  return ret;
}
string igs(string s) {
  int i = 0;
  while (i < s.size()) {
    if (s[i] == ' ' && (i == 0 || !isdigit(s[i - 1]) || i + 1 == s.size() ||
                        !isdigit(s[i + 1])))
      s.erase(i, 1);
    else
      i++;
  }
  return s;
}
bool isame(map<vi, int> a, map<vi, int> b) {
  map<vi, int> x, y;
  for (auto p : a)
    if (p.second != 0) x[p.first] = p.second;
  for (auto p : b)
    if (p.second != 0) y[p.first] = p.second;
  return x == y;
}
int main() {
  while (true) {
    getline(cin, s);
    if (s[0] == '.') {
      puts(".");
      break;
    }
    s = igs(s);
    int it = 0;
    map<vi, int> ms = expr(it);
    while (true) {
      getline(cin, s);
      if (s[0] == '.') break;
      s = igs(s);
      it = 0;
      if (isame(expr(it), ms))
        puts("yes");
      else
        puts("no");
    }
  }
}
