#include <bits/stdc++.h>
using namespace std;
string s;
int p, len;
vector<pair<int, vector<pair<char, int> > > > add(
    vector<pair<int, vector<pair<char, int> > > > a,
    vector<pair<int, vector<pair<char, int> > > > b) {
  map<vector<pair<char, int> >, int> mp;
  for (int i = 0; i < (int)a.size(); i++) {
    mp[a[i].second] += a[i].first;
  }
  for (int i = 0; i < (int)b.size(); i++) {
    mp[b[i].second] += b[i].first;
  }
  vector<pair<int, vector<pair<char, int> > > > res;
  map<vector<pair<char, int> >, int>::iterator it;
  for (it = mp.begin(); it != mp.end(); it++) {
    if (it->second == 0) continue;
    res.push_back(pair<int, vector<pair<char, int> > >(it->second, it->first));
  }
  sort(res.begin(), res.end());
  return res;
}
pair<int, vector<pair<char, int> > > mul(
    pair<int, vector<pair<char, int> > > a,
    pair<int, vector<pair<char, int> > > b) {
  int fi = a.first * b.first;
  vector<pair<char, int> > &va = a.second;
  vector<pair<char, int> > &vb = b.second;
  map<char, int> mp;
  for (int i = 0; i < (int)va.size(); i++) {
    pair<char, int> p = va[i];
    mp[p.first] += p.second;
  }
  for (int j = 0; j < (int)vb.size(); j++) {
    pair<char, int> p = vb[j];
    mp[p.first] += p.second;
  }
  vector<pair<char, int> > se;
  if (fi == 0) {
    return pair<int, vector<pair<char, int> > >(fi, se);
  }
  map<char, int>::iterator it;
  for (it = mp.begin(); it != mp.end(); it++) {
    se.push_back(*it);
  }
  return pair<int, vector<pair<char, int> > >(fi, se);
}
vector<pair<int, vector<pair<char, int> > > > mul(
    vector<pair<int, vector<pair<char, int> > > > a,
    vector<pair<int, vector<pair<char, int> > > > b) {
  map<vector<pair<char, int> >, int> mp;
  for (int i = 0; i < (int)a.size(); i++) {
    pair<int, vector<pair<char, int> > > as = a[i];
    for (int j = 0; j < (int)b.size(); j++) {
      pair<int, vector<pair<char, int> > > bs = b[j];
      pair<int, vector<pair<char, int> > > c = mul(as, bs);
      mp[c.second] += c.first;
    }
  }
  vector<pair<int, vector<pair<char, int> > > > res;
  map<vector<pair<char, int> >, int>::iterator it;
  for (it = mp.begin(); it != mp.end(); it++) {
    if (it->second == 0) continue;
    res.push_back(pair<int, vector<pair<char, int> > >(it->second, it->first));
  }
  return res;
}
vector<pair<int, vector<pair<char, int> > > > target;
vector<pair<int, vector<pair<char, int> > > > solve();
vector<pair<int, vector<pair<char, int> > > > getNum() {
  while (s[p] == ' ') p++;
  if ('0' <= s[p] && s[p] <= '9') {
    int res = 0;
    while ('0' <= s[p] && s[p] <= '9') {
      res = res * 10 + (s[p] - '0');
      p++;
    }
    vector<pair<int, vector<pair<char, int> > > > re;
    vector<pair<char, int> > r;
    if (res > 0) re.push_back(pair<int, vector<pair<char, int> > >(res, r));
    return re;
  }
  if ('(' == s[p]) {
    p++;
    vector<pair<int, vector<pair<char, int> > > > res = solve();
    p++;
    return res;
  }
  char ch = s[p++];
  while (s[p] == ' ') p++;
  int num = 1;
  if (s[p] == '^') {
    vector<pair<int, vector<pair<char, int> > > > tmp = getNum();
    num = tmp[0].first;
    assert(num > 0);
  }
  vector<pair<int, vector<pair<char, int> > > > res;
  vector<pair<char, int> > r;
  r.push_back(pair<char, int>(ch, num));
  res.push_back(pair<int, vector<pair<char, int> > >(1, r));
  return res;
}
vector<pair<int, vector<pair<char, int> > > > solve() {
  while (s[p] == ' ') p++;
  stack<vector<pair<int, vector<pair<char, int> > > > > st;
  st.push(getNum());
  while (1) {
    while (s[p] == ' ') p++;
    if (p >= len) {
      break;
    } else if (s[p] == '+') {
      p++;
      vector<pair<int, vector<pair<char, int> > > > num = getNum();
      st.push(num);
    } else if (s[p] == '-') {
      p++;
      vector<pair<int, vector<pair<char, int> > > > num = getNum();
      for (int i = 0; i < (int)num.size(); i++) num[i].first *= -1;
      st.push(num);
    } else if (s[p] == ')') {
      break;
    } else {
      vector<pair<int, vector<pair<char, int> > > > num = getNum();
      vector<pair<int, vector<pair<char, int> > > > A = st.top();
      st.pop();
      st.push(mul(A, num));
    }
  }
  vector<pair<int, vector<pair<char, int> > > > res = st.top();
  st.pop();
  while (!st.empty()) {
    res = add(res, st.top());
    st.pop();
  }
  for (int i = 0; i < (int)res.size(); i++) {
    sort(res[i].second.begin(), res[i].second.end());
  }
  sort(res.begin(), res.end());
  return res;
}
int main() {
  while (1) {
    getline(cin, s);
    if (s == ".") break;
    p = 0;
    len = s.size();
    target = solve();
    while (1) {
      getline(cin, s);
      if (s == ".") break;
      p = 0;
      len = s.size();
      vector<pair<int, vector<pair<char, int> > > > tmp = solve();
      if (target == tmp)
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
    cout << '.' << endl;
  }
  return 0;
}
