#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

using K = string;
using M = map<K, int>;

K mul(K k1, K k2){
	k1 += k2;
	sort(k1.begin(), k1.end());
	return k1;
}

M add(M m1, M m2){
	for(auto v : m2){
		m1[v.first] += v.second;
	}
	return m1;
}

M mul(M m1, M m2){
	M ret;
	for(const auto& v1 : m1){
		for(const auto& v2 : m2){
			K k = mul(v1.first, v2.first);
			ret[k] += v1.second * v2.second;
		}
	}
	return ret;
}

M pow(M m, int x){
	M ret;
	ret[""] = 1;
	M a = m;
	while(x){
		if(x & 1) ret = mul(ret, a);
		x /= 2;
		a = mul(a, a);
	}
	return ret;
}

int c;
int N;
string s;

M exp();
M term();
M fact();

void skip(){
	while(c < N && (s[c] == ' ')) c++;
}

M exp(){
	skip();
	M t1 = term();

	skip();
	while(c < N && (s[c] == '+' || s[c] == '-')){
		char ch = s[c];
		c++;
		skip();
		M t2 = term();
		if(ch == '-'){
			for(auto& v : t2){
				v.second *= -1;
			}
		}
		t1 = add(t1, t2);
	}
	return t1;
}

M term(){
	skip();
	M f1 = fact();
	skip();
	while(c < N && (isalnum(s[c]) || s[c] == '(')){
		M f2 = fact();
		skip();
		f1 = mul(f1, f2);
	}
	return f1;
}

M fact(){
	skip();
	M r;
	if(s[c] == '('){
		c++;
		r = exp();
		c++;
		skip();
	}
	else if(isalpha(s[c])){
		K k;
		k += s[c];
		c++;
		r[k]++;
	}
	else if(isdigit(s[c])){
		int x = 0;
		while(c < N && isdigit(s[c])){
			x = x * 10 + s[c] - '0';
			c++;
		}
		r[""] += x;
	}
	skip();
	if(c < N && s[c] == '^'){
		c++;
		skip();
		int x = s[c] - '0';
		c++;
		skip();
		r = pow(r, x);
	}
	return r;
}

M f(string t){
	c = 0;
	s = t;
	N = s.size();
	return exp();
}

M filter(M m){
	M ret;
	for(auto v : m){
		if(v.second == 0) continue;
		ret[v.first] = v.second;
	}
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	//auto ret = f("a- (b-c)+2");

	string x, y;
	while(getline(cin, x), x != "."){
		M xm = filter(f(x));
		while(getline(cin, y), y != "."){
			auto res = filter(f(y));
			if(xm == res){
				cout << "yes" << endl;
			}
			else{
				cout << "no" << endl;
			}
		}
		cout << "." << endl;
	}
}