#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

typedef map<vi, int> E;

E operator+(E a, const E &b){
	each(i, b) a[i->first] += i->second;
	return a;
}
E operator-(E a, const E &b){
	each(i, b) a[i->first] -= i->second;
	return a;
}
E operator*(const E &a, const E &b){
	E c;
	each(i, a) each(j, b){
		vi v = i->first;
		rep(k, 26) v[k] += (j->first)[k];
		c[v] += i->second * j->second;
	}
	return c;
}
int p;
string in, next;
E expr();
void get(){
	next = "";
	while(p < in.size() && isspace(in[p])) p++;
	if(p >= in.size()) return;
	if(isdigit(in[p])){
		while(p < in.size() && isdigit(in[p])) next += in[p++];
	}else{
		next += in[p++];
	}
}
E primary(){
	E res;
	if(isdigit(next[0])){
		vi v(26);
		res[v] = atoi(next.c_str());
		return res;
	}
	if(isalpha(next[0])){
		vi v(26);
		v[next[0] - 'a'] = 1;
		res[v] = 1;
		return res;
	}
	get();
	res = expr();
	return res;
}
E factor(){
	E res = primary();
	get();
	if(next == "^"){
		get();
		int d = atoi(next.c_str()) - 1;
		E e = res;
		while(d--) res = res * e;
		get();
	}
	return res;
}
E term(){
	E res;
	while(1){
		E f = factor();
		if(res.empty()) res = f;
		else res = res * f;
		if(next == "" || next == "+" || next == "-" || next ==")") break;
	}
	return res;
}
E expr(){
	E t = term();
	while(next == "+" || next == "-"){
		bool op = next == "+";
		get();
		E u = term();
		if(op) t = t + u;
		else t = t - u;
	}
	return t;
}

E parse(){
	p = 0;
	get();
	return expr();
}
int main(){
	while(getline(cin, in), in != "."){
		E a = parse();
		while(getline(cin, in), in != ".")
			cout << (a == parse() ? "yes" : "no") << endl;
		cout << "." << endl;
	}
	return 0;
}