#include <iostream>
#include <string>
#include <cctype>
#include <map>
#include <algorithm>
using namespace std;

typedef long long ll;

string norm(string s)
{
	string res;
	for(int i=0; i<s.size(); i++) {
		res += s[i];
		while(s[i] == ' ') i++;
		if(i!=0 && s[i-1] == ' ') res += s[i];
	}

	s = res;
	res = "";

	for(int i=0; i<s.size(); i++) {
		if(s[i]==' ' && !(isdigit(s[i-1]) && isdigit(s[i+1]))) continue;
		
		res += s[i];
	}

	s = res;
	res = "";
	for(int i=0; i<s.size(); i++) {
		if(s[i] == ' ') {
			res += '*';
		}

		else {
			res += s[i];
			if(isalnum(s[i]) && s[i+1] == '(' ||
				s[i]=='(' && s[i+1] == ')' ||
				s[i]==')' && s[i+1] == '(' ||
				s[i]==')' && isalnum(s[i+1]) ||
				isalnum(s[i]) && isalpha(s[i+1]) ||
				isalpha(s[i]) && isalnum(s[i+1])) {
				res += '*';
		
			}
		}
	}

	return res;
}



class Polynomial
{
public:
	map<string, ll> tem;
	Polynomial() 
	{
		tem["Digit"] = 0;
	}

	Polynomial(ll k) 
	{
		tem["Digit"] = k;
	}

	Polynomial(char a)
	{
		tem[string(1,a)] = 1;
		tem["Digit"] = 0;
	}

	void add(Polynomial& p)
	{
		map<string, ll>::iterator it = p.tem.begin();
		for(; it != p.tem.end(); it++) {
			if(it->second == 0) continue;

			if(!tem.count(it->first)) tem[it->first] = it->second;
			else tem[it->first] += it->second;
		}
	}

	void sub(Polynomial& p)
	{
		map<string, ll>::iterator it = p.tem.begin();
		for(; it != p.tem.end(); it++) {
			if(it->second == 0) continue;

			if(!tem.count(it->first)) tem[it->first] = -it->second;
			else tem[it->first] -= it->second;
		}

	}

	void mul(Polynomial& p)
	{
		Polynomial tmp;

		map<string, ll>::iterator pit = p.tem.begin();
		map<string, ll>::iterator it = tem.begin();
		for(; it != tem.end(); it++) 
		for(pit = p.tem.begin(); pit != p.tem.end(); pit++) {
			string nt;

			if(it->first == "Digit" && pit->first == "Digit") {
				nt = it->first;
			}
			else if(it->first == "Digit") {
				nt = pit->first;
			}
			else if(pit->first == "Digit") {
				nt = it->first;
			}
			else {
				nt = string(it->first) + string(pit->first);
				sort(nt.begin(), nt.end()); 
			}

			ll k = it->second * pit->second;
			

			if(k==0) continue;

			if(!tmp.tem.count(nt)) tmp.tem[nt] = k;
			else tmp.tem[nt] += k;
		}

		*this = tmp;
	}

	void pow(Polynomial& p)
	{
		int pw = p.tem["Digit"];
		
		Polynomial res(1LL);
		Polynomial tmp = *this;
		for(int i=0; i<pw; i++)
			res.mul(tmp);

		*this = res;
	}

	bool equals(Polynomial& p) {
		map<string, ll>::iterator pit = p.tem.begin();
		map<string, ll>::iterator it = tem.begin();

		for(; it != tem.end(); ++it) {
			if(p.tem.count(it->first) == 0) {
				if(it->second != 0) return false;
			}
			else {
				if(it->second != p.tem[it->first]) return false;
			}
		}

		for(; pit != p.tem.end(); ++pit) {
			if(tem.count(pit->first) == 0) {
				if(pit->second != 0) return false;
			}
			else {
				if(pit->second != tem[pit->first]) return false;
			}
		}

		return true;
	}
};

string str;
int p;

Polynomial expr();
Polynomial term();
Polynomial factor();
Polynomial primary();
Polynomial digit();

Polynomial expr()
{
	Polynomial a = term();
	while(str[p] == '+' || str[p] == '-') {
		char op = str[p++];
		Polynomial b = term();

		if(op == '+') a.add(b);
		if(op == '-') a.sub(b);
	}

	return a;
}

Polynomial term()
{
	Polynomial a = factor();
	while(str[p] == '*') {
		char op = str[p++];
		Polynomial b = factor();

		a.mul(b);
	}

	return a;
}

Polynomial factor()
{
	Polynomial a = primary();
	if(str[p] == '^') {
		p++;

		Polynomial pw = digit();
		a.pow(pw);
	}

	return a;
}

Polynomial primary()
{
	Polynomial a;
	if(isdigit(str[p])) {
		a = digit();
	}
	else if(isalpha(str[p])) {
		a = Polynomial(str[p]);
		p++;
	}
	else {
		p++;
		a = expr();
		p++;
	}

	return a;
}

Polynomial digit()
{
	ll res = 0;
	while(isdigit(str[p])) {
		res *= 10;
		res += str[p] - '0';
		p++;
	}

	return Polynomial(res);
}

Polynomial parse()
{
	p = 0;
	str += '$';
	str = norm(str);
	//cout << str << endl;

	return expr();
}

int main()
{
	while(1) {
		getline(cin, str);
		if(str == ".") break;
		Polynomial a = parse();

		while(1) {
			getline(cin, str);
			if(str == ".") {
				cout << str << endl;
				break;
			}
			Polynomial b = parse();

			cout << (a.equals(b) ? "yes":"no") << endl;
		}
	}
}

Measured memory_bytes: 1080