// AOJ 1233: Equals are Equals
// 2017.12.23 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define HSIZ 199
typedef struct { char *s; int id; } HASH;
HASH hash[HSIZ+2], *hashend = hash + HSIZ;

int lookup(char *s, int id)
{
	int w = strlen(s);
	int i = (101 * *s + 103 * *(s+w-1) + 107 * w) % HSIZ;
	HASH *tp = hash + i;

	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return tp->id;
		if (++tp == hashend) tp = hash;
	}
	tp->s = s, tp->id = id;
	return -1;
}

#define INF 0x7fffffff
typedef struct { int c, var; } T; // var < 0: constants
T ans[101]; int alen;
T stu[101]; int slen;
char s[102];
char var[100][100]; int sz;

char *parse();

int cmp(char *a, char *b) { return (int)(*a - *b); }

int norm(T *a, int len)
{
	int i, j, f, tlen;
	T t[101];

	f = 0;
	for (i = 0; i < len; i++) {
		if (a[i].c == INF) continue;
		for (j = i+1; j < len; j++) {
			if (a[j].c == INF) continue;
			if (a[j].var == a[i].var) a[i].c += a[j].c, a[j].c = INF, f = 1;
		}
	}
	if (!f) return len;
	memcpy(t, a, sizeof(T)*len), tlen = len;
	len = 0; for (j = 0; j < tlen; j++) {
		if (t[j].c == INF) continue;
		a[len].c = t[j].c, a[len++].var = t[j].var;
	}
	return len;
}

int add(T *a, int alen, T *b, int blen, int op)
{
	int i, j;

	for (i = 0; i < blen; i++) {
		for (j = 0; ; j++) {
			if (j == alen) {
				a[alen].c = op ? b[i].c: -b[i].c;
				a[alen++].var = b[i].var;
				break;
			}
			if (b[i].var == a[j].var) {
				if (op) a[j].c += b[i].c;
				else    a[j].c -= b[i].c;
				break;
			}
		}
	}
	return alen;
}

int mul(T *a, int alen, T *b, int blen)
{
	int i, j, id, tlen;
	T t[101];
	char s[100], *p;

	tlen = 0;
	for (i = 0; i < alen; i++) for (j = 0; j < blen; j++) {
		t[tlen].c = a[i].c * a[j].c;
		if (     a[i].var < 0) t[tlen].var = b[j].var;
		else if (b[j].var < 0) t[tlen].var = a[i].var;
		else {
			p = var[a[i].var], strcpy(s, p);
			p = var[b[j].var], strcat(s, p);
			qsort(s, strlen(s), 1, cmp);
			strcpy(var[sz], s);
			id = lookup(var[sz], sz);
			if (id < 0) id = sz++;
			t[tlen].var = id;
		}
		tlen++;
	}
	memcpy(a, t, sizeof(T)*tlen);
	alen = norm(a, tlen);
	return alen;
}


int eq(T *a, int alen, T *b, int blen)
{
	int i, j;
	
	for (i = 0; i < alen; i++) {
		if (a[i].c == 0) continue;
		for (j = 0; ; j++) {
			if (j == blen) return 0;
			if (a[i].var == b[j].var) {
				if (a[i].c != b[i].c) return 0;
				break;
			}
		}
	}
	for (i = 0; i < blen; i++) {
		if (b[i].c == 0) continue;
		for (j = 0; ; j++) {
			if (j == alen) return 0;
			if (b[i].var == a[j].var) {
				if (b[i].c != a[j].c) return 0;
				break;
			}
		}
	}
	return 1;
}

char *factor(T *q, int *len, char *p)
{
	int c, x, w, id;
	char a[100];

	while (isspace(*p)) p++;
	if (*p == '(') {
		p++; while (isspace(*p)) p++;
		p = parse(q, len, p);
		while (isspace(*p)) p++;
		if (*p == ')') p++;
	} else {
		w = 0, c = 1;
		while (1) {
			while (isspace(*p)) p++;
			if (isdigit(*p)) {
				x = 0; while (isdigit(*p)) x = 10*x + (*p++ & 0xf);
				c *= x;
			} else if (isalpha(*p)) {
				id = *p++;
				while (isspace(*p)) p++;
				x = 1;
				if (*p == '^') {
					p++;
					while (isspace(*p)) p++;
					if (isdigit(*p)) {
						x = 0; while (isdigit(*p)) x = 10*x + (*p++ & 0xf);
					}
				}
				while (x--) a[w++] = id;
			} else break;
		}
		if (w == 0) q[*len].var = -1;
		else {
			qsort(a, w, 1, cmp), a[w] = 0;
			strcpy(var[sz], a);
			id = lookup(var[sz], sz);
			if (id < 0) id = sz++;
			q[*len].var = id;
		}
		q[*len].c = c;
		(*len)++;
	}
	return p;
}

char *term(T *q, int *len, char *p)
{
	int tlen;
	T t[101];

	p = factor(q, len, p);
	while (1) {
		while (isspace(*p)) p++;
		if (*p == '(' || *p == ')' || *p == '+' || *p == '-') break;
		if (*p < ' ') break;
		tlen = 0; p = factor(t, &tlen, p);
		*len = mul(q, *len, t, tlen);
	}
	return p;
}

char *parse(T *q, int *len, char *p)
{
	int op, tlen;
	T t[101];

	p = term(q, len, p);
	*len = norm(q, *len);
	while (1) {
		while (isspace(*p)) p++;
		if      (*p == '+') op = 1;
		else if (*p == '-') op = 0;
		else break;
		p++;
		tlen = 0; p = term(t, &tlen, p);
		*len = add(q, *len, t, tlen, op);
		*len = norm(q, *len);
	}
	return p;
}

int main()
{
	while (fgets(s, 100, stdin) && *s != '.') {
		memset(hash, 0, sizeof(hash));
		alen = 0; parse(ans, &alen, s);
		alen = norm(ans, alen);

		while (fgets(s, 100, stdin) && *s != '.') {
			slen = 0; parse(stu, &slen, s);
			slen = norm(stu, slen);

			puts(eq(ans, alen, stu, slen) ? "yes" : "no");
		}
		puts(".");
	}
	return 0;
}