#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 convertS(){
    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 if(isdigit(s[i-1])&&isdigit(s[i+1]))s[i]='*';
            else s.erase(s.begin()+i--);
        }
        if(isdigit(s[i])&&isalpha(s[i+1]))s.insert(s.begin()+i+1,'*');
        if(isalpha(s[i])&&isalpha(s[i+1]))s.insert(s.begin()+i+1,'*');
        if(isalpha(s[i])&&isdigit(s[i+1]))s.insert(s.begin()+i+1,'*');
        if(s[i]==')'&&isalpha(s[i+1]))s.insert(s.begin()+i+1,'*');
        if(s[i]==')'&&isdigit(s[i+1]))s.insert(s.begin()+i+1,'*');
        if(s[i+1]=='('&&isalpha(s[i]))s.insert(s.begin()+i+1,'*');
        if(s[i+1]=='('&&isdigit(s[i]))s.insert(s.begin()+i+1,'*');
        if(s[i+1]=='('&&s[i]==')')s.insert(s.begin()+i+1,'*');
    }
}
void convertT(){
    r(i,t.size()){
        if(i&&t[i]==' '){
            if(t[i-1]==')'&&t[i+1]=='(')t[i]='*';
            else if(isalpha(t[i-1])&&isalpha(t[i+1]))t[i]='*';
            else if(t[i-1]==')'&&isalpha(t[i+1]))t[i]='*';
            else if(isalpha(t[i-1])&&t[i+1]=='(')t[i]='*';
            else if(t[i-1]==')'&&isdigit(t[i+1]))t[i]='*';
            else if(isdigit(t[i-1])&&t[i+1]=='(')t[i]=='*';
            else if(isdigit(t[i-1])&&isalpha(t[i+1]))t[i]='*';
            else if(isalpha(t[i-1])&&isdigit(t[i+1]))t[i]='*';
            else if(isdigit(t[i-1])&&isdigit(t[i+1]))t[i]='*';
            else t.erase(t.begin()+i--);
        }
        if(isdigit(t[i])&&isalpha(t[i+1]))t.insert(t.begin()+i+1,'*');
        if(isalpha(t[i])&&isalpha(t[i+1]))t.insert(t.begin()+i+1,'*');
        if(isalpha(t[i])&&isdigit(t[i+1]))t.insert(t.begin()+i+1,'*');
        if(t[i]==')'&&isalpha(t[i+1]))t.insert(t.begin()+i+1,'*');
        if(t[i]==')'&&isdigit(t[i+1]))t.insert(t.begin()+i+1,'*');
        if(t[i+1]=='('&&isalpha(t[i]))t.insert(t.begin()+i+1,'*');
        if(t[i+1]=='('&&isdigit(t[i]))t.insert(t.begin()+i+1,'*');
        if(t[i+1]=='('&&t[i]==')')t.insert(t.begin()+i+1,'*');
    }
}
int Sbnf1();
int get_S(){
    int res=0;
    if(s[p]=='(')p++,res=Sbnf1(),p++;
    else if(isdigit(s[p])){
        while(isdigit(s[p])){
            res=res*10+(s[p++]-'0');
        }
    }
    else res=m[s[p++]];
    return res%mod;
}
int Sbnf3(){
    int res=get_S();
    while(s[p]=='^'){
        p++;
        int ret=get_S(),kit=res;
        r(i,ret-1){
            res*=kit;
            res=res%mod;
        }
    }
    return res%mod;
}
int Sbnf2(){
    int res=Sbnf3();
    while(s[p]=='*'){
        p++;
        res*=Sbnf3();
        res=res%mod;
    }
    return res%mod;
}
int Sbnf1(){
    int res=Sbnf2();
    while(s[p]=='+'||s[p]=='-'){
        int pp=p++;
        if(s[pp]=='+')res+=Sbnf2();
        if(s[pp]=='-')res-=Sbnf2();
        while(res<0)res+=mod;
        res=res%mod;
    }
    return res%mod;
}
int Tbnf1();
int get_T(){
    int res=0;
    if(t[p]=='(')p++,res=Tbnf1(),p++;
    else if(isdigit(t[p])){
        while(isdigit(t[p])){
            res=res*10+(t[p++]-'0');
        }
    }
    else res=m[t[p++]];
    return res%mod;
}
int Tbnf3(){
    int res=get_T();
    while(t[p]=='^'){
        p++;
        int ret=get_T(),kit=res;
        r(i,ret-1){
            res*=kit;
            res=res%mod;
        }
    }
    return res%mod;
}
int Tbnf2(){
    int res=Tbnf3();
    while(t[p]=='*'){
        p++;
        res*=Tbnf3();
        res=res%mod;
    }
    return res%mod;
}
int Tbnf1(){
    int res=Tbnf2();
    while(t[p]=='+'||t[p]=='-'){
        int pp=p++;
        if(t[pp]=='+')res+=Tbnf2();
        if(t[pp]=='-')res-=Tbnf2();
        while(res<0)res+=mod;
        res=res%mod;
    }
    return res%mod;
}
main(){
    while(getline(cin,t)){
        if(t==".")break;
        convertT();
        while(getline(cin,s)){
            if(s=="."){
                cout<<'.'<<endl;
                break;
            }
            int flag = 0;
            convertS();
            r(i,100){
                r(j,26)m[j+'a']=rand()%mod;
                p=0;
                int y=Tbnf1()%mod;
                p=0;
                int x=Sbnf1()%mod;
                if(y!=x)flag++;
            }
            cout<<(flag?"no":"yes")<<endl;
        }
    }
}

Measured memory_bytes: 3140