#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
using namespace std;
string s,t;
int p;
map<char,int>m;
void convert(string &s){
    r(i,s.size()){
        if(i&&s[i]==' '){
            if(s[i-1]==')'&&s[i+1]=='(')s[i]='*';
            else if(isalpha(s[i-1])&&isalpha(s[i+1]))s[i]=='*';
            else if(s[i-1]==')'&&isalpha(s[i+1]))s[i]='*';
            else if(isalpha(s[i-1])&&s[i+1]=='(')s[i]=='*';
            else if(s[i-1]==')'&&isdigit(s[i+1]))s[i]='*';
            else if(isdigit(s[i-1])&&s[i+1]=='(')s[i]=='*';
            else if(isdigit(s[i-1])&&isalpha(s[i+1]))s[i]=='*';
            else if(isalpha(s[i-1])&&isdigit(s[i+1]))s[i]=='*';
            else s.erase(s.begin()+i--);
        }
    }
}
int Sbnf1();
int get_S(){
    int res=0;
    if(s[p]=='(')p++,res=Sbnf1(),p++;
    else res=m[s[p++]];
    return res;
}
int Sbnf3(){
    int res=get_S();
    while(s[p]=='^'){
        p++;
        int ret=get_S(),kit=res;
        r(i,ret){
            res*=kit;
            res=res%mod;
        }
    }
    return res;
}
int Sbnf2(){
    int res=Sbnf3();
    while(s[p]=='*'){
        p++;
        res*=Sbnf3();
        res=res%mod;
    }
    return res;
}
int Sbnf1(){
    int res=Sbnf2();
    while(s[p]=='+'||s[p]=='-'){
        int pp=p++;
        if(s[pp]=='+')res+=Sbnf2();
        if(s[pp]=='-')res-=Sbnf2();
        if(res<0)res=(res+mod)%mod;
        else res=res%mod;
    }
    return res;
}
int Tbnf1();
int get_T(){
    int res=0;
    if(t[p]=='(')p++,res=Sbnf1(),p++;
    else res=m[t[p++]];
    return res;
}
int Tbnf3(){
    int res=get_T();
    while(t[p]=='^'){
        p++;
        int ret=get_T(),kit=res;
        r(i,ret){
            res*=kit;
            res=res%mod;
        }
    }
    return res;
}
int Tbnf2(){
    int res=Tbnf3();
    while(t[p]=='*'){
        p++;
        res*=Tbnf3();
        res=res%mod;
    }
    return res;
}
int Tbnf1(){
    int res=Tbnf2();
    while(t[p]=='+'||t[p]=='-'){
        int pp=p++;
        if(t[pp]=='+')res+=Tbnf2();
        if(t[pp]=='-')res-=Tbnf2();
        if(res<0)res=(res+mod)%mod;
        else res=res%mod;
    }
    return res;
}
main(){
    while(getline(cin,t)){
        if(t==".")break;
        convert(t);
        while(getline(cin,s)){
            if(s=="."){
                cout<<'.'<<endl;
                break;
            }
            int flag = 0;
            convert(s);
            r(i,100){
                m.clear();
                r(j,26)m[j+'a']=rand();
                p=0;
                int y=Tbnf1();
                p=0;
                int x=Sbnf1();
                if(y!=x)flag++;
            }
            cout<<(flag?"no":"yes")<<endl;
        }
    }
}