#include <iostream>

using namespace std;
string gs,s,s2;
int n,fr[28],ok,c;
int main()
{
    cin >> gs;
    for(int i = 0; i < gs.size(); i++)
        fr[gs[i]-'a']=1;
    cin >> s;
    for(int i = 0 ;i <s.size(); i++)if(s[i]=='*')c = 1;

    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> s2;
        if(c==0)
        {
            if(s.size()!=s2.size())cout <<"NO\n";
            else
            {
                ok =1;
                for(int i =0; i <s.size() && ok; i++)
                if(isalpha(s[i]))
                {
                    if(s2[i]!=s[i])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                if(ok==1)cout <<"YES\n";
            }
        }
        else
        {
            if(s2.size()<s.size()-1)
            {
                cout <<"NO\n";
                ok=0;
            }
            int i =0;
            ok =1;
            while(s[i]!='*' && ok)
            {
                if(isalpha(s[i]))
                {
                    if(s2[i]!=s[i])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                i++;
            }
            if(s2.size() == s.size() - 1 && ok == 1)
            {
            while(i < s2.size())
            {
                if(isalpha(s[i + 1]))
                {
                    if(s2[i]!=s[i+ 1])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                i++;
            }
                if(ok == 1)cout <<"YES\n";
            }
            else if(ok ==1)
            {int j = s.size() -1;
            int q=s2.size() -1;
            while(s[j]!='*' && ok)
            {
                if(q<i)
                    {
                        break;
                    }
                if(isalpha(s[j]))
                {
                    if(s2[q]!=s[j])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[q]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                q--;
                j--;
            }
            for(int v=i;v<=q && ok;v++)if(fr[s2[v]-'a']==1)
            {
                        cout << "NO\n";
                        ok =0;
                        break;
            }
            if(ok == 1)cout <<"YES\n";
            }

        }
    }
    return 0;
}


#include <iostream>

using namespace std;
string gs,s,s2;
int n,fr[28],ok;
int main()
{
    cin >> gs;
    for(int i = 0; i < gs.size(); i++)
        fr[gs[i]-'a']=1;
    cin >> s;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> s2;
        if(s2.size()<s.size() - 1)cout <<"NO\n";
        else
        {
            ok = 1;
            for(int i = 0; i < s.size(); i++)
            if(isalpha(s[i]))
            {
                if(s[i] != s2[i])
                {
                    cout <<"NO\n";
                    ok = 0;
                    break;
                }
            }
            else
            {
                if(s[i] == '?')
                {
                    if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                    if(s2.size() >= s.size())
                    for(int j = 1; j < s2.size() - s.size() + 1; j++,i++)
                    if(fr[s2[i]-'a'] == 1)
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }

                }
            }
            if(ok == 1)cout << "YES\n";
        }
    }
    return 0;
}


#include <iostream>

using namespace std;
string gs,s,s2;
int n,fr[28],ok,c;
int main()
{
    cin >> gs;
    for(int i = 0; i < gs.size(); i++)
        fr[gs[i]-'a']=1;
    cin >> s;
    for(int i = 0 ;i <s.size(); i++)if(s[i]=='*')c = 1;

    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> s2;
        if(c==0)
        {
            if(s.size()!=s2.size())cout <<"NO\n";
            else
            {
                ok =1;
                for(int i =0; i <s.size() && ok; i++)
                if(isalpha(s[i]))
                {
                    if(s2[i]!=s[i])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                if(ok==1)cout <<"YES\n";
            }
        }
        else
        {
            int i =0;
            ok =1;
            while(s[i]!='*' && ok)
            {
                if(isalpha(s[i]))
                {
                    if(s2[i]!=s[i])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                i++;
            }
            if(s2.size() == s.size() - 1 && ok == 1)
            {
            while(i < s2.size())
            {
                if(isalpha(s[i + 1]))
                {
                    if(s2[i]!=s[i+ 1])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                i++;
            }
                if(ok == 1)cout <<"YES\n";
            }
            else if(ok ==1)
            {int j = s.size() -1;
            int q=s2.size() -1;
            while(s[j]!='*' && ok)
            {
                if(q<i)
                    {
                        break;
                    }
                if(isalpha(s[j]))
                {
                    if(s2[q]!=s[j])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[q]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                q--;
                j--;
            }
            for(int v=i;v<=q && ok;v++)if(fr[s2[v]-'a']==1)
            {
                        cout << "NO\n";
                        ok =0;
                        break;
            }
            if(ok == 1)cout <<"YES\n";
            }

        }
    }
    return 0;
}


#include <iostream>

using namespace std;
string gs,s,s2;
int n,fr[28],ok,c;
int main()
{
    cin >> gs;
    for(int i = 0; i < gs.size(); i++)
        fr[gs[i]-'a']=1;
    cin >> s;
    for(int i = 0 ;i <s.size(); i++)if(s[i]=='*')c = 1;

    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> s2;
        if(s2.size()<s.size()-1)cout <<"NO\n";
        else if(c==0)
        {
            if(s.size()!=s2.size())cout <<"NO\n";
             else
            {
                ok =1;
                for(int i =0; i <s.size() && ok; i++)
                if(isalpha(s[i]))
                {
                    if(s2[i]!=s[i])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                if(ok==1)cout <<"YES\n";
            }
        }
        else
        {
            int i =0;
            ok =1;
            while(s[i]!='*' && ok)
            {
                if(isalpha(s[i]))
                {
                    if(s2[i]!=s[i])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                i++;
            }
            if(ok == 1)
            {
                int j = s.size() -1;
                int q=s2.size() -1;
                while(s[j]!='*' && ok)
                {
                    if(q<i)
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                    if(isalpha(s[j]))
                    {
                        if(s2[q]!=s[j])
                        {
                            cout <<"NO\n";
                            ok =0;
                            break;
                        }
                    }
                    else
                    {
                        if(fr[s2[q]-'a'] != 1)
                        {
                            cout << "NO\n";
                            ok =0;
                            break;
                        }
                    }
                    q--;
                    j--;
                }
            if(q!=i)
            for(int v=i;v<=q && ok;v++)if(fr[s2[v]-'a']==1)
            {
                        cout << "NO\n";
                        ok =0;
                        break;
            }
            if(ok == 1)cout <<"YES\n";
            }

        }
    }
    return 0;
}


#include <iostream>

using namespace std;
string gs,s,s2;
int n,fr[28],ok;
int main()
{
    cin >> gs;
    for(int i = 0; i < gs.size(); i++)
        fr[gs[i]-'a']=1;
    cin >> s;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> s2;
        if(s2.size()<s.size() - 1)cout <<"NO\n";
        else
        {
            ok = 1;
            for(int i = 0,j =0 ; i < s2.size(); i++,j ++)
            if(isalpha(s[j]))
            {
                if(s[j] != s2[i])
                {
                    cout <<"NO\n";
                    ok = 0;
                    break;
                }
            }
            else
            {
                if(s[j] == '?')
                {
                    if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                    if(s2.size() >= s.size())
                    for(int q = 1; q < s2.size() - s.size() + 1; q++,i++)
                    if(fr[s2[i]-'a'] == 1)
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }

                }
            }
            if(ok == 1)cout << "YES\n";
        }
    }
    return 0;
}


#include <iostream>

using namespace std;
string gs,s,s2;
int n,fr[28],ok,c;
int main()
{
    cin >> gs;
    for(int i = 0; i < gs.size(); i++)
        fr[gs[i]-'a']=1;
    cin >> s;
    for(int i = 0 ;i <s.size(); i++)if(s[i]=='*')c = 1;

    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> s2;
        if(s2.size()<s.size()-1)cout <<"NO\n";
        else if(c==0)
        {
            if(s.size()!=s2.size())cout <<"NO\n";
             else
            {
                ok =1;
                for(int i =0; i <s.size() && ok; i++)
                if(isalpha(s[i]))
                {
                    if(s2[i]!=s[i])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                if(ok==1)cout <<"YES\n";
            }
        }
        else
        {
            int i =0;
            ok =1;
            while(s[i]!='*' && ok)
            {
                if(isalpha(s[i]))
                {
                    if(s2[i]!=s[i])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                i++;
            }
            if(ok == 1)
            {
                int j = s.size() -1;
                int q=s2.size() -1;
                while(s[j]!='*' && ok)
                {
                    if(q<i)
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                    if(isalpha(s[j]))
                    {
                        if(s2[q]!=s[j])
                        {
                            cout <<"NO\n";
                            ok =0;
                            break;
                        }
                    }
                    else
                    {
                        if(fr[s2[q]-'a'] != 1)
                        {
                            cout << "NO\n";
                            ok =0;
                            break;
                        }
                    }
                    q--;
                    j--;
                }
            for(int v=i;v<=q && ok;v++)if(fr[s2[v]-'a']==1)
            {
                        cout << "NO\n";
                        ok =0;
                        break;
            }
            if(ok == 1)cout <<"YES\n";
            }

        }
    }
    return 0;
}


#include <iostream>

using namespace std;
string gs,s,s2;
int n,fr[28],ok,c;
int main()
{
    cin >> gs;
    for(int i = 0; i < gs.size(); i++)
        fr[gs[i]-'a']=1;
    cin >> s;
    for(int i = 0 ;i <s.size(); i++)if(s[i]=='*')c = 1;

    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> s2;
        if(c==0)
        {
            if(s.size()!=s2.size())cout <<"NO\n";
            else
            {
                ok =1;
                for(int i =0; i <s.size() && ok; i++)
                if(isalpha(s[i]))
                {
                    if(s2[i]!=s[i])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                if(ok==1)cout <<"YES\n";
            }
        }
        else
        {
            int i =0;
            ok =1;
            while(s[i]!='*' && ok)
            {
                if(isalpha(s[i]))
                {
                    if(s2[i]!=s[i])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                i++;
            }
            if(ok ==1)
            {int j = s.size() -1;
            int q=s2.size() -1;
            while(s[j]!='*' && ok)
            {
                if(q<i)
                    {
                        break;
                    }
                if(isalpha(s[j]))
                {
                    if(s2[q]!=s[j])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[q]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                q--;
                j--;
            }
            if(q!=i)
            for(int v=i;v<=q && ok;v++)if(fr[s2[v]-'a']==1)
            {
                        cout << "NO\n";
                        ok =0;
                        break;
            }
            if(ok == 1)cout <<"YES\n";
            }

        }
    }
    return 0;
}


#include <iostream>

using namespace std;
string gs,s,s2;
int n,fr[28],ok,c;
int main()
{
    cin >> gs;
    for(int i = 0; i < gs.size(); i++)
        fr[gs[i]-'a']=1;
    cin >> s;
    for(int i = 0 ;i <s.size(); i++)if(s[i]=='*')c = 1;

    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> s2;
        if(c==0)
        {
            if(s.size()!=s2.size())cout <<"NO";
            else
            {
                ok =1;
                for(int i =0; i <s.size(); i++)
                if(isalpha(s[i]))
                {
                    if(s2[i]!=s[i])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                if(ok==1)cout <<"YES\n";
            }
        }
        else
        {
            int i =0;
            ok =1;
            while(s[i]!='*')
            {
                if(isalpha(s[i]))
                {
                    if(s2[i]!=s[i])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                i++;
            }
            if(ok ==1)
            {int j = s.size() -1;
            int q=s2.size() -1;
            while(s[j]!='*')
            {
                if(q<i)
                    {
                        break;
                    }
                if(isalpha(s[j]))
                {
                    if(s2[q]!=s[j])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[q]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                q--;
                j--;
            }
            if(q!=i)
            for(int v=i;v<=q;v++)if(fr[s2[v]-'a']==1)
            {
                        cout << "NO\n";
                        ok =0;
                        break;
            }
            if(ok == 1)cout <<"YES\n";
            }

        }
    }
    return 0;
}


#include <iostream>

using namespace std;
string gs,s,s2;
int n,fr[28],ok;
int main()
{
    cin >> gs;
    for(int i = 0; i < gs.size(); i++)
        fr[gs[i]-'a']=1;
    cin >> s;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> s2;
        if(s2.size()<s.size() - 1)cout <<"NO\n";
        else
        {
            ok = 1;
            for(int i = 0,j =0 ; i < s2.size(); i++,j++)
            if(isalpha(s[j]))
            {
                if(s[j] != s2[i])
                {
                    cout <<"NO\n";
                    ok = 0;
                    break;
                }
            }
            else
            {
                if(s[j] == '?')
                {
                    if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                    if(s2.size() >= s.size())
                    {
                        int q;
                        for(q = 1; q < s2.size() - s.size() + 1; q++,i++)
                    if(fr[s2[i]-'a'] == 1)
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                    if(q>1)i--;
                    }
                    if(ok ==0)break;

                }
            }
            if(ok == 1)cout << "YES\n";
        }
    }
    return 0;
}


#include <iostream>

using namespace std;
string gs,s,s2;
int n,fr[28],ok,c;
int main()
{
    cin >> gs;
    for(int i = 0; i < gs.size(); i++)
        fr[gs[i]-'a']=1;
    cin >> s;
    for(int i = 0 ;i <s.size(); i++)if(s[i]=='*')c = 1;

    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> s2;
        if(c==0)
        {
            if(s.size()!=s2.size())cout <<"NO\n";
            else
            {
                ok =1;
                for(int i =0; i <s.size(); i++)
                if(isalpha(s[i]))
                {
                    if(s2[i]!=s[i])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                if(ok==1)cout <<"YES\n";
            }
        }
        else
        {
            int i =0;
            ok =1;
            while(s[i]!='*')
            {
                if(isalpha(s[i]))
                {
                    if(s2[i]!=s[i])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                i++;
            }
            if(ok ==1)
            {int j = s.size() -1;
            int q=s2.size() -1;
            while(s[j]!='*')
            {
                if(q<i)
                    {
                        break;
                    }
                if(isalpha(s[j]))
                {
                    if(s2[q]!=s[j])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[q]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                q--;
                j--;
            }
            if(q!=i)
            for(int v=i;v<=q;v++)if(fr[s2[v]-'a']==1)
            {
                        cout << "NO\n";
                        ok =0;
                        break;
            }
            if(ok == 1)cout <<"YES\n";
            }

        }
    }
    return 0;
}


#include <iostream>

using namespace std;
string gs,s,s2;
int n,fr[28],ok,c;
int main()
{
    cin >> gs;
    for(int i = 0; i < gs.size(); i++)
        fr[gs[i]-'a']=1;
    cin >> s;
    for(int i = 0 ;i <s.size(); i++)if(s[i]=='*')c = 1;

    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> s2;
        if(s2.size()<s.size()-1)cout <<"NO\n";
        else if(c==0)
        {
            if(s.size()!=s2.size())cout <<"NO\n";
             else
            {
                ok =1;
                for(int i =0; i <s.size() && ok; i++)
                if(isalpha(s[i]))
                {
                    if(s2[i]!=s[i])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                if(ok==1)cout <<"YES\n";
            }
        }
        else
        {
            int i =0;
            ok =1;
            while(s[i]!='*' && ok)
            {
                if(isalpha(s[i]))
                {
                    if(s2[i]!=s[i])
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                }
                else
                {
                     if(fr[s2[i]-'a'] != 1)
                    {
                        cout << "NO\n";
                        ok =0;
                        break;
                    }
                }
                i++;
            }
            if(ok == 1)
            {
                int j = s.size() -1;
                int q=s2.size() -1;
                if(q==i)cout<<"YES\n";
                else
                {while(s[j]!='*' && ok)
                {
                    if(q<i)
                    {
                        cout <<"NO\n";
                        ok =0;
                        break;
                    }
                    if(isalpha(s[j]))
                    {
                        if(s2[q]!=s[j])
                        {
                            cout <<"NO\n";
                            ok =0;
                            break;
                        }
                    }
                    else
                    {
                        if(fr[s2[q]-'a'] != 1)
                        {
                            cout << "NO\n";
                            ok =0;
                            break;
                        }
                    }
                    q--;
                    j--;
                }
            for(int v=i;v<=q && ok;v++)if(fr[s2[v]-'a']==1)
            {
                        cout << "NO\n";
                        ok =0;
                        break;
            }
            if(ok == 1)cout <<"YES\n";}
            }

        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	string a,b,c;
	int n;
	while(cin>>a>>b>>n){
		for(int j=1;j<=n;j++){
			cin>>c;
			int lb=b.length();
			int lc=c.length();
			if(b.find('*')==-1){
				if(lb!=lc){
					cout<<"No"<<endl;
					continue;
				}
				else{
					int t=0;
					for(int i=0;i<lb;i++){
						if(b[i]!=c[i]){
							if(b[i]!='?'||a.find(c[i])==-1){
								cout<<"No"<<endl;
								t++;
								break;
							}
						}
					}
					if(t==0){
						cout<<"Yes"<<endl;
					}
				}
			}
			else{
				if(lc<lb-1){
					cout<<"No"<<endl;
					continue;
				}
				int t=b.find('*');
			/*	string p1,p2;
				p2=b.erase(0,t+1);
				p1=b.erase(t,lb-t);
			//	cout<<p1<<" "<<p2<<endl;
				int l1=p1.length();
				int l2=p2.length();*/
				int f=0;
				for(int i=t-1;i>=0;i--){
					if(b[i]!=c[i]){
						if(b[i]!='?'||a.find(c[i])==-1){
							cout<<"No"<<endl;
							f++;
							break;
						}
					}
				}
			//	cout<<f<<" *1 "<<endl;
				if(f==0){
					for(int i=t;i<=lc-lb+t;i++){
						if(a.find(c[i])!=-1){
							cout<<"No"<<endl;
							f++;
							break;
						}
					}
				}
			//	cout<<f<<" *2 "<<endl;
				if(f==0){
					for(int i=1;i<lb-t;i++){
						if(b[lb-i]!=c[lc-i]){
							if(b[lb-i]!='?'||a.find(c[lc-i])==-1){
								cout<<"No"<<endl;
								f++;
								break;
							}
						}
					}
				}
			//	cout<<f<<" *3 "<<endl;
				if(f==0){
					cout<<"Yes"<<endl;
				}
			}
		}

	}
	return 0;
}


#include<iostream>
#include<cmath>
#include<cstring>
char asc[30],f[100010],g[100010];
using namespace std;
int main()
{
    memset(f,0,sizeof(f));
    static int ascl[150];
    int n,flag=0,dd;
    cin>>asc;
    for(int i=0;i<strlen(asc);i++)
    {
        ascl[asc[i]]++;
    }
    cin>>f;
    for(int i=0;i<strlen(f);i++)
    {
        if(f[i]=='*')
        {
            flag=1;
            dd=i;
        }
    }
    cin>>n;
    if(flag==0)
    {
        for(int x=0;x<n;x++)
        {
            int flagg=0;
            memset(g,0,sizeof(g));
            cin>>g;
            int N=strlen(g);
            for(int i=0;i<N;i++)
            {
                if(f[i]=='?')
                {
                    if(ascl[g[i]]==0)
                    {
                        cout<<"NO"<<endl;
                        flagg=1;
                        break;
                    }
                }
                else
                {
                    if(f[i]!=g[i])
                    {
                        cout<<"NO"<<endl;
                        flagg=1;
                        break;
                    }
                }
            }
            if(flagg==0)
            {
                cout<<"YES"<<endl;
            }
        }
    }
    else
    {
        for(int x=0;x<n;x++)
        {
            int flagg=0,len=0;
            memset(g,0,sizeof(g));
            cin>>g;
            int N=strlen(g);
            for(int i=0;i<dd;i++)
            {
                if(f[i]=='?')
                {
                    if(ascl[g[i]]==0)
                    {
                        cout<<"NO"<<endl;
                        flagg=1;
                        break;
                    }
                }
                else
                {
                    if(f[i]!=g[i])
                    {
                        cout<<"NO"<<endl;
                        flagg=1;
                        break;
                    }
                }
            }
            len=N-strlen(f)+1;
            dd=dd+len;
            for(int i=dd-1;i>=dd-len;i--)
            {
                if(ascl[g[i]]==1)
                {
                    cout<<"NO"<<endl;
                    flagg=1;
                    break;
                }
            }
            if(flagg==0)
            {
                for(int i=dd;i<N;i++)
                {
                    if(f[i-len+1]=='?')
                    {
                        if(ascl[g[i]]==0)
                        {
                            cout<<"NO"<<endl;
                            flagg=1;
                            break;
                        }
                    }
                    else
                    {
                        if(f[i-len+1]!=g[i])
                        {
                            cout<<"NO"<<endl;
                            flagg=1;
                            break;
                        }
                    }
                }
                if(flagg==0)
                {
                    cout<<"YES"<<endl;
                }
            }
            dd=dd-len;
        }
    }
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <set>
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MS(a) memset(a,0,sizeof(a))
#define MS1(a) memset(a,1,sizeof(a))
using namespace std;

struct node{};
const int N=10;

string str1,str2,str3;// str1有*  str2没*
int n,len;
bool book[128],flag=0;//flag  是否有*

bool input(){
    MS(book);
    string ch;
    cin>>ch;
    len=ch.length();
    for(int i=0;i<len;i++)
        book[ch[i]]=1;
    cin>>str1;
    int temp;
    len=str1.length();
    if((temp=str1.find("*"))!=string::npos){
        flag=1;str2=str1.substr(0,temp);str3=str1.substr(temp+1,len-temp-1);
    }
    scanf("%d",&n);
    return true;
}

int main(){
    input();
    while(n--){
        string t;
        cin>>t;
        int l=t.length();
        bool f=1;
        if(!flag&&len==l){
            for(int i=0;i<l;i++){
                if(str1[i]=='?'){
                    if(!book[t[i]]){f=0;break;}
                }else if(str1[i]!=t[i]){f=0;break;}
            }
        }else if(flag&&len-1<=l){
            int len2=str2.length();
            for(int i=0;i<len2;i++){
                if(str2[i]=='?'){
                    if(!book[t[i]]){f=0;break;}
                }else if(str2[i]!=t[i]){f=0;break;}
            }
            int len3=str3.length();
            for(int i=len2;i<l-len3;i++){
                if(book[t[i]]){f=0;break;}
            }
            for(int i=len3-1,j=l-1;i>=0;i--,j--){
                if(str3[i]=='?'){
                    if(!book[t[j]]){f=0;break;}
                }else if(str3[i]!=t[j]){f=0;break;}
            }
        }else f=0;
        if(f)printf("YES\n");
        else printf("NO\n");
    }
}


#include <bits/stdc++.h>
using namespace std;
char b[100000],c[100000];
int main()
{
	char a[26];
	int n,ans=0;
	cin>>a;
    cin>>b;
    cin>>n;
    for(int j=0;j<strlen(b);j++)
    {
        if(b[j]=='*') ans=1;
    }
    for(int i=1;i<=n;i++)
    {
        memset(c,0,strlen(c));
        cin>>c;
        int found=1;
        if(ans==1&&strlen(b)-strlen(c)>=2)
        {
            cout<<"NO"<<endl;
            continue;
        }
        else if(ans==0&&strlen(b)!=strlen(c))
        {
            cout<<"NO"<<endl;
            continue;
        }
        else
        {
            int o=0;
            for(int h=0;found==1&&h<strlen(c);h++)
            {
                int l;
                for(l=0;l<strlen(a);l++)
                {
                    if(c[h]==a[l]) break;
                }
                if(l==strlen(a))
                {//如果等于则是坏的字母
                    if(b[o]!='*')
                    {
                        cout<<"NO"<<endl;
                        found=0;
                        break;
                    }
                    else if(b[o]=='*')
                    {
                        if(b[o+1]==c[h+1])
                        {
                            o=o+2;
                            continue;
                        }
                        else continue;
                    }
                }
                else
                {//否则为好的字母
                    if(b[o]=='?' || b[o]==c[h] )
                    {
                        o=o+1;
                        continue;
                    }
                    else
                    {
                        cout<<"NO"<<endl;
                        found=0;
                        break;
                    }
                }
            }
        }
        if(found==1)
        {
        cout<<"YES"<<endl ;
        }
    }
	return 0;
}


#include<iostream>
#include<cmath>
#include<cstring>
char asc[30],f[100010],g[100010];
using namespace std;
int main()
{
    memset(f,0,sizeof(f));
    static int ascl[150];
    int n,flag=0,dd;
    cin>>asc;
    for(int i=0;i<strlen(asc);i++)
        ascl[asc[i]]=1;
    cin>>f;
    for(int i=0;i<strlen(f);i++)
        if(f[i]=='*'){flag=1;dd=i;}
    int NF=strlen(f);
    cin>>n;
    for(int x=0;x<n;x++)
    {
        int flagg=0;
        memset(g,0,sizeof(g));
        cin>>g;
        int N=strlen(g);
        if(flag==0)
        {
            if(N!=NF)
                flagg=1;
            else
            {
                for(int i=0;i<N;i++)
                {
                    if(f[i]=='?')
                        if(ascl[g[i]]==0) {flagg=1; break;}
                    else
                        if(f[i]!=g[i]) {flagg=1;break;}
                }
            }
        }
        else
        {
            for(int i=0;i<dd;i++)
            {
                if(f[i]=='?')
                    if(ascl[g[i]]==0) {flagg=1;break;}
                else
                    if(f[i]!=g[i]) {flagg=1;break;}
            }
            for(int i=dd+N-NF;i>=dd;i--)
                if(ascl[g[i]]==1) {flagg=1;break;}
            if(flagg==0)
            {
                for(int y=N-1,z=NF-1;z>dd;y--,z--)
                {
                    if(y<dd){flagg=1; break;}
                    if(f[z]=='?')
                        if(ascl[g[y]]==0){flagg=1; break;}
                    else
                        if(f[z]!=g[y]){flagg=1;break;}
                }
            }
        }
        if(flagg==0) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
char asc[26],f[100010],g[100010];
using namespace std;
int main()
{
    memset(f,0,sizeof(f));
    static int ascl[150];
    int n,flag=0,dd;
    scanf("%s",asc);
    for(int i=0;i<strlen(asc);i++)
    {
        ascl[asc[i]]++;
    }
    scanf("%s",f);
    for(int i=0;i<strlen(f);i++)
    {
        if(f[i]=='*')
        {
            flag=1;
            dd=i;
        }
    }
    scanf("%d",&n);
    getchar();
    if(flag==0)
    {
        for(int x=0;x<n;x++)
        {
            int flagg=0;
            memset(g,0,sizeof(g));
            gets(g);
            int N=strlen(g);
            for(int i=0;i<N;i++)
            {
                if(f[i]=='?')
                {
                    if(ascl[g[i]]==0)
                    {
                        printf("NO\n");
                        flagg=1;
                        break;
                    }
                }
                else
                {
                    if(f[i]!=g[i])
                    {
                        printf("NO\n");
                        flagg=1;
                        break;
                    }
                }
            }
            if(flagg==0)
            {
                printf("YES\n");
            }
        }
    }
    else
    {
        for(int x=0;x<n;x++)
        {
            int flagg=0,len=0;
            memset(g,0,sizeof(g));
            gets(g);
            int N=strlen(g);
            for(int i=0;i<dd;i++)
            {
                if(f[i]=='?')
                {
                    if(ascl[g[i]]==0)
                    {
                        printf("NO\n");
                        flagg=1;
                        break;
                    }
                }
                else
                {
                    if(f[i]!=g[i])
                    {
                        printf("NO\n");
                        flagg=1;
                        break;
                    }
                }
            }
            len=N-strlen(f)+1;
            dd=dd+len;
            for(int i=dd-1;i>=dd-len;i--)
            {
                if(ascl[g[i]]==1)
                {
                    printf("NO\n");
                    flagg=1;
                    break;
                }
            }
            if(flagg==0)
            {
                for(int i=dd;i<N;i++)
                {
                    if(f[i-len+1]=='?')
                    {
                        if(ascl[g[i]]==0)
                        {
                            printf("NO\n");
                            flagg=1;
                            break;
                        }
                    }
                    else
                    {
                        if(f[i-len+1]!=g[i])
                        {
                            printf("NO\n");
                            flagg=1;
                            break;
                        }
                    }
                }
                if(flagg==0)
                {
                    printf("YES\n");
                }
            }
            dd=dd-len;
        }
    }
}


#include<iostream>
#include<cmath>
#include<cstring>
char asc[30],f[100010],g[100010];
using namespace std;
int main()
{
    memset(f,0,sizeof(f));
    static int ascl[150];
    int n,flag=0,dd;
    cin>>asc;
    for(int i=0;i<strlen(asc);i++)
        ascl[asc[i]]=1;
    cin>>f;
    for(int i=0;i<strlen(f);i++)
    {
        if(f[i]=='*')
        {
            flag=1;
            dd=i;
        }
    }
    int NF=strlen(f);
    cin>>n;
    for(int x=0;x<n;x++)
    {
        int flagg=0;
        memset(g,0,sizeof(g));
        cin>>g;
        int N=strlen(g);
        if(flag==0)
        {
            if(N!=NF)
                flagg=1;
            else
            {
                for(int i=0;i<N;i++)
                {
                    if(f[i]=='?')
                    {
                        if(ascl[g[i]]==0)
                        {
                            flagg=1;
                            break;
                        }
                    }
                    else
                    {
                        if(f[i]!=g[i])
                        {
                            flagg=1;
                            break;
                        }
                    }
                }
            }
        }
        else
        {
            for(int i=0;i<dd;i++)
            {
                if(f[i]=='?')
                {
                    if(ascl[g[i]]==0)
                    {
                        flagg=1;
                        break;
                    }
                }
                else
                {
                    if(f[i]!=g[i])
                    {
                        flagg=1;
                        break;
                    }
                }
            }
            for(int i=dd+N-NF;i>=dd;i--)
            {
                if(ascl[g[i]]==1)
                {
                    flagg=1;
                    break;
                }
            }
            if(flagg==0)
            {
                for(int y=N-1,z=NF-1;z>dd;y--,z--)
                {
                    if(y<dd)
                    {
                        flagg=1;
                        break;
                    }
                    if(f[z]=='?')
                    {
                        if(ascl[g[y]]==0)
                        {
                            flagg=1;
                            break;
                        }
                    }
                    else
                    {
                        if(f[z]!=g[y])
                        {
                            flagg=1;
                            break;
                        }
                    }
                }
            }
        }
        if(flagg==0)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }
}


#include<iostream>
#include<cmath>
#include<cstring>
char asc[30],f[100010],g[100010];
using namespace std;
int main()
{
    memset(f,0,sizeof(f));
    static int ascl[150];
    int n,flag=0,dd;
    cin>>asc;
    for(int i=0;i<strlen(asc);i++)
    {
        ascl[asc[i]]=1;
    }
    cin>>f;
    for(int i=0;i<strlen(f);i++)
    {
        if(f[i]=='*')
        {
            flag=1;
            dd=i;
        }
    }
    cin>>n;
    if(flag==0)
    {
        for(int x=0;x<n;x++)
        {
            int flagg=0;
            memset(g,0,sizeof(g));
            cin>>g;
            int N=strlen(g);
            if(N!=strlen(f))
            {
                cout<<"NO"<<endl;
                flagg=1;
            }
            else
            {
                for(int i=0;i<N;i++)
                {
                    if(f[i]=='?')
                    {
                        if(ascl[g[i]]==0)
                        {
                            cout<<"NO"<<endl;
                            flagg=1;
                            break;
                        }
                    }
                    else
                    {
                        if(f[i]!=g[i])
                        {
                            cout<<"NO"<<endl;
                            flagg=1;
                            break;
                        }
                    }
                }
                if(flagg==0)
                {
                    cout<<"YES"<<endl;
                }
            }
        }
    }
    else
    {
        for(int x=0;x<n;x++)
        {
            int flagg=0,len=0;
            memset(g,0,sizeof(g));
            cin>>g;
            int N=strlen(g);
            for(int i=0;i<dd;i++)
            {
                if(f[i]=='?')
                {
                    if(ascl[g[i]]==0)
                    {
                        cout<<"NO"<<endl;
                        flagg=1;
                        break;
                    }
                }
                else
                {
                    if(f[i]!=g[i])
                    {
                        cout<<"NO"<<endl;
                        flagg=1;
                        break;
                    }
                }
            }
            len=N-strlen(f)+1;
            dd=dd+len;
            for(int i=dd-1;i>=dd-len;i--)
            {
                if(ascl[g[i]]==1)
                {
                    cout<<"NO"<<endl;
                    flagg=1;
                    break;
                }
            }
            if(flagg==0)
            {
                for(int y=N-1, z=strlen(f)-1;y>=dd;y--,z--)
                {
                    if(f[z]=='?')
                    {
                        if(ascl[g[y]]==0)
                        {
                            cout<<"NO"<<endl;
                            flagg=1;
                            break;
                        }
                    }
                    else
                    {
                        if(f[z]!=g[y])
                        {
                            cout<<"NO"<<endl;
                            flagg=1;
                            break;
                        }
                    }
                }
                if(flagg==0)
                {
                    cout<<"YES"<<endl;
                }
            }
            dd=dd-len;
        }
    }
}


#include<iostream>
#include<cmath>
#include<cstring>
char asc[26],f[100010],g[100010];
using namespace std;
int main()
{
    static int ascl[150];
    int n,flag=0,dd;
    cin>>asc;
    for(int i=0;i<strlen(asc);i++)
    {
        ascl[asc[i]]++;
    }
    cin>>f;
    for(int i=0;i<strlen(f);i++)
    {
        if(f[i]=='*')
        {
            flag=1;
            dd=i;
        }
    }
    cin>>n;
    if(flag==0)
    {
        for(int x=0;x<n;x++)
        {
            int flagg=0;
            memset(g,0,sizeof(g));
            cin>>g;
            int N=strlen(g);
            for(int i=0;i<N;i++)
            {
                if(f[i]=='?')
                {
                    if(ascl[g[i]]==0)
                    {
                        cout<<"NO"<<endl;
                        flagg=1;
                        break;
                    }
                }
                else
                {
                    if(f[i]!=g[i])
                    {
                        cout<<"NO"<<endl;
                        flagg=1;
                        break;
                    }
                }
            }
            if(flagg==0)
            {
                cout<<"YES"<<endl;
            }
        }
    }
    else
    {
        for(int x=0;x<n;x++)
        {
            int flagg=0,len=0;
            memset(g,0,sizeof(g));
            cin>>g;
            int N=strlen(g);
            for(int i=0;i<dd;i++)
            {
                if(f[i]=='?')
                {
                    if(ascl[g[i]]==0)
                    {
                        cout<<"NO"<<endl;
                        flagg=1;
                        break;
                    }
                }
                else
                {
                    if(f[i]!=g[i])
                    {
                        cout<<"NO"<<endl;
                        flagg=1;
                        break;
                    }
                }
            }
            len=N-strlen(f)+1;
            dd=dd+len;
            for(int i=dd-1;i>=dd-len;i--)
            {
                if(ascl[g[i]]==1)
                {
                    cout<<"NO"<<endl;
                    flagg=1;
                    break;
                }
            }
            if(flagg==0)
            {
                for(int i=dd;i<N;i++)
                {
                    if(f[i-len+1]=='?')
                    {
                        if(ascl[g[i]]==0)
                        {
                            cout<<"NO"<<endl;
                            flagg=1;
                            break;
                        }
                    }
                    else
                    {
                        if(f[i-len+1]!=g[i])
                        {
                            cout<<"NO"<<endl;
                            flagg=1;
                            break;
                        }
                    }
                }
                if(flagg==0)
                {
                    cout<<"YES"<<endl;
                }
            }
            dd=dd-len;
        }
    }
}


#include<iostream>
#include<cmath>
#include<cstring>
char asc[30],f[100010],g[100010];
using namespace std;
int main()
{
    memset(f,0,sizeof(f));
    static int ascl[150];
    int n,flag=0,dd;
    cin>>asc;
    for(int i=0;i<strlen(asc);i++)
        ascl[asc[i]]=1;
    cin>>f;
    for(int i=0;i<strlen(f);i++)
    {
        if(f[i]=='*')
        {
            flag=1;
            dd=i;
        }
    }
    int NF=strlen(f);
    cin>>n;
    if(flag==0)
    {
        for(int x=0;x<n;x++)
        {
            int flagg=0;
            memset(g,0,sizeof(g));
            cin>>g;
            int N=strlen(g);
            if(N!=NF)
                flagg=1;
            else
            {
                for(int i=0;i<N;i++)
                {
                    if(f[i]=='?')
                    {
                        if(ascl[g[i]]==0)
                        {
                            flagg=1;
                            break;
                        }
                    }
                    else
                    {
                        if(f[i]!=g[i])
                        {
                            flagg=1;
                            break;
                        }
                    }
                }
            }
            if(flagg==0)
                cout<<"YES"<<endl;
            else
                cout<<"NO"<<endl;
        }
    }
    else
    {
        for(int x=0;x<n;x++)
        {
            int flagg=0,len=0;
            memset(g,0,sizeof(g));
            cin>>g;
            int N=strlen(g);
            for(int i=0;i<dd;i++)
            {
                if(f[i]=='?')
                {
                    if(ascl[g[i]]==0)
                    {
                        flagg=1;
                        break;
                    }
                }
                else
                {
                    if(f[i]!=g[i])
                    {
                        flagg=1;
                        break;
                    }
                }
            }
            for(int i=dd+N-NF;i>=dd;i--)
            {
                if(ascl[g[i]]==1)
                {
                    flagg=1;
                    break;
                }
            }
            if(flagg==0)
            {
                for(int y=N-1,z=NF-1;z>dd;y--,z--)
                {
                    if(y<dd)
                    {
                        flagg=1;
                        break;
                    }
                    if(f[z]=='?')
                    {
                        if(ascl[g[y]]==0)
                        {
                            flagg=1;
                            break;
                        }
                    }
                    else
                    {
                        if(f[z]!=g[y])
                        {
                            flagg=1;
                            break;
                        }
                    }
                }
            }
            if(flagg==0)
                cout<<"YES"<<endl;
            else
                cout<<"NO"<<endl;
        }
    }
}


#include <iostream>
#include <cstdio>
using namespace std;
int main() {
	string a,b;
	cin>>a>>b;
	bool good[26]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	for(int i=0;i<a.size();i++){
		good[a[i]-97]=1;
	}
	int n;
	cin>>n;
	while(n--){
		string c;
		cin>>c;
		int ans=0;
		for(int i=0;i<c.size();i++){
			if(b[ans]=='*'){
				if(good[c[i]-97]){
					while(b[ans]=='*'){
						ans++;
					}
				}else {
					if(i==c.size()-1)cout<<"YES"<<endl;
					continue;
				}
			}
			if(b[ans]=='?'){
				if(good[c[i]-97]){
					ans++;
				}else{
					cout<<"NO"<<endl;
					break;
				}
			}else{
				if(b[ans]==c[i]){
					ans++;
				}else{
					cout<<"NO"<<endl;
					break;
				}
			}
			if(i==c.size()-1)cout<<"YES"<<endl;
		}
	}
}


#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
char asc[26],f[100010],g[100010];
using namespace std;
int main()
{
    static int ascl[150];
    int n,flag=0,h[50000],ii=0,dd;
    cin>>asc;
    for(int i=0;i<strlen(asc);i++)
    {
        ascl[asc[i]]++;
    }
    cin>>f;
    for(int i=0;i<strlen(f);i++)
    {

        if(f[i]=='*')
        {
            flag=1;
            dd=i;
        }
        else if(f[i]=='?')
        {
            h[ii]=i;
            ii++;
        }
    }
    cin>>n;
    if(flag==0)
    {
        for(int i=0;i<n;i++)
        {
            int flagg=0,iii=0;
            memset(g,0,sizeof(g));
            cin>>g;
            int N=strlen(g);
            for(int i=0;i<N;i++)
            {
                if(i==h[iii])
                {
                    if(ascl[g[h[i]]]==0)
                    {
                        cout<<"No"<<endl;
                        flagg=1;
                        break;
                    }
                    iii++;
                }
                else
                {
                    if(g[i]!=f[i])
                    {
                        cout<<"No"<<endl;
                        flagg=1;
                        break;
                    }
                }
            }
            if(flagg==0)
            {
                cout<<"Yes"<<endl;
            }
        }
    }
    else
    {
        for(int i=0;i<n;i++)
        {
            int flagg=0,len=0,iii=0;
            memset(g,0,sizeof(g));
            cin>>g;
            int N=strlen(g);
            for(int i=0;i<dd;i++)
            {
                if(i==h[iii])
                {
                    if(ascl[g[h[i]]]==0)
                    {
                        cout<<"No"<<endl;
                        flagg=1;
                        break;
                    }
                    iii++;
                }
                else
                {
                    if(g[i]!=f[i])
                    {
                        cout<<"No"<<endl;
                        flagg=1;
                        break;
                    }
                }
            }
            while(ascl[g[dd]]==0&&dd<N)
            {
                len++;
                dd++;
            }
            if(flagg==0)
            {
                for(int i=dd;i<N;i++)
                {
                    if(i==h[iii])
                    {
                        if(ascl[g[h[i]]]==0)
                        {
                            cout<<"No"<<endl;
                            flagg=1;
                            break;
                        }
                        iii++;
                    }
                    else
                    {
                        if(g[i]!=f[i-len+1])
                        {
                            cout<<"No"<<endl;
                            flagg=1;
                            break;
                        }
                    }
                }
                if(flagg==0)
                {
                    cout<<"Yes"<<endl;
                }
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
char b[100000],c[100000];
int main(){
	char a[26];
	int n;
	cin>>a;
cin>>b;
cin>>n;
for(int i=1;i<=n;i++){
	memset(c,0,strlen(c));
	cin>>c;
	int found=1,ans=0;
	for(int j=0;j<strlen(b);j++){
		if(b[j]=='*') ans=1;
	}
	if(ans==1&&strlen(b)-strlen(c)>=2){
		cout<<"NO"<<endl;
		continue;
	}
	else if(ans==0&&strlen(b)!=strlen(c)){
			cout<<"NO"<<endl;
		continue;
	}
	else{
		int o=0;
	for(int h=0;found==1&&h<strlen(c);h++){
	int l;
	for(l=0;l<strlen(a);l++){
		if(c[h]==a[l]) break;
	}
	if(l==strlen(a)){//如果等于则是坏的字母
	 if(b[o]==c[h]){
	o=o+1;
	continue;
	}
	else if(b[o]!='*'){
	 cout<<"NO"<<endl;
		found=0;
	}
else if(b[o]=='*'){
	if(b[o+1]==c[h]){
		o=o+2;
		continue;
	}
	else continue;
}
	else continue;
	}
	else{//否则为好的字母
		if(b[o]=='?' || b[o]==c[h] ){
			o=o+1;
			continue;
		}
		else if(b[o]=='*'){
			o++;
			h--;
		}
		else{
	cout<<"NO"<<endl;
		found=0;
		}
	}
}
}
	if(found==1){
	cout<<"YES"<<endl ;
	}
}
	return 0;
	}


#include<bits/stdc++.h>
#define for_int register int
#define endl '\n'
#define ll long long
#define ld long double
#define op operator
#define max(a, b)  (!((a) < (b)) ? (a) : (b))
#define min(a, b)  ((a) < (b) ? (a) : (b))
//#pragma GCC optimize(3)
//#pragma GCC diagnostic error "-std=c++14"
//#pragma GCC target("avx")
//#pragma GCC optimize("Ofast")
using namespace std;
string s,s1,s2;
bool dis[31];
int n;
int main(){
	cin>>s;
	for(for_int i=0; i<s.length(); i++){
		dis[s[i]-'a'+1]=1;
	}
	cin>>s1;
	cin>>n;
	getchar();
	for(for_int i=1; i<=n; i++){
		int len=0;
		do{
			char c=getchar();
			if(c=='\n') break;
			s2[len++]=c;
		}while(1);
		int k=0,f=0;
		for(for_int j=0; j<len; j++){
			if(s1[k]=='?'){
				if(dis[s2[j]-'a'+1]==0){
					f=1;
					puts("NO");
					break;
				}
			} else if (s1[k]=='*'){
				while(1){
					if(dis[s2[j]-'a'+1]==0){
						++j;
					} else {
						j--;
						break;
					}
				}
			} else {
				if(s1[k]!=s2[j]){
					f=1;
					puts("NO");
					break;
				}
			}
			k++;
		}
		if(k<s1.length()&&f==0&&s1[s1.length()-1]!='*') puts("NO");
		else if(f==0)puts("YES");
	}
    return 0;
}


#include<bits/stdc++.h>
#define INF     1e9
#define ld      long double
#define lli     long long int
#define PI 	    acos(-1)
#define read    freopen("in.txt","r",stdin)
#define uu		first
#define vv		second
#define write   freopen("out.txt","w",stdout)
#define pii     pair<int,int>
using namespace std;
string gd,str,ask;
int q,n,t,ans,tmp,cnt,ara[1000];
int main()
{
	cin>>gd>>str>>n;
	for(int i=0;i<gd.size();i++) ara[ gd[i] - 'a' ] = 1;
	while(n--) {
		cin>>ask;
		int in=-1,fin=-1;
		ans=0;

		for(int i=0;i< max(str.size(), ask.size() );i++) {
			if( str[i]== '?') {
				if( ara[ ask[i] - 'a' ] != 1) {
					ans=2;
					break;
				}
			}
			else if( str[i] == '*' ) {
				in=i;
				break;
			}
			else {
				if( str[i] != ask[i]) {
					ans=2;
					break;
				}
			}
		}

		if(ans==2) {
			printf("NO\n");
			continue;
		}
		else if(in==-1) {
			printf("YES\n");
			continue;
		}
		else {

			for(int i=str.size()-1 ,j=ask.size()-1; i>=in && j>=in; i--,j--) {
				if( str[i]== '?') {
					if( ara[ ask[j] - 'a' ] != 1) {
						ans=2;
						break;
					}
				}
				else if( str[i] == '*' ) {
					fin=j;
					break;
				}
				else {
					if( str[i] != ask[j]) {
						ans=2;
						break;
					}
				}
			}
		}

		if(ans==2) {
			printf("NO\n");
			continue;
		}

		else {
			for(int i=in; i<=fin;i++ ) {
				if( ara[ ask[i] - 'a' ] == 1 ) {
					ans=2;
					break;
				}
			}
		}

		if(ans==2) {
			printf("NO\n");
		}
		else printf("YES\n");
	}
	return 0;
}


#include<bits/stdc++.h>
#define INF     1e9
#define ld      long double
#define lli     long long int
#define PI 	    acos(-1)
#define read    freopen("in.txt","r",stdin)
#define uu		first
#define vv		second
#define write   freopen("out.txt","w",stdout)
#define pii     pair<int,int>
using namespace std;
string gd,in,str,baal;
int n,tmp,cnt,flg,ara[30];
int main()
{
    cin>>gd>>in>>n;
    for(int i=0;i<gd.size();i++) {
        ara[ gd[i]-'a' ]=1;
    }
    while(n--) {
        cin>>str;
        flg=0;
        if(str.size()==in.size()) {
            for(int i=0;i<str.size();i++) {
                if(in[i]=='?') {
                    if( ara[ str[i]-'a' ]==0) {
                        flg=1;
                        break;
                    }
                }
                else if(in[i]=='*') {
                    if( ara[ str[i]-'a' ]==1) {
                        flg=1;
                        break;
                    }
                }
                else {
                    if(in[i]!=str[i]) {
                        flg=1;
                        break;
                    }
                }
            }
        }
        else if(in.size()-str.size()==1) {
            /*for(int i=0;i<in.size();i++) {
                if(in[i]!='*') baal[cnt++]=in[i];
            }
            cout<<in<<" "<<baal<<" wtf"<<endl;*/
            //if(in.size()==str.size()) {
                for(int i=0,cnt=0;i<str.size();i++,cnt++) {
                    if(in[cnt]=='*') {
                        cnt++;
                    }
                    else if(in[cnt]=='?') {
                        if( ara[ str[i]-'a' ]==0) {
                            flg=1;
                            break;
                        }
                    }
                    else {
                        if(in[cnt]!=str[i]) {
                            flg=1;
                            break;
                        }
                    }

                }
            //}
            //else flg=1;
        }
        else flg=1;

        if(flg==1) printf("NO\n");
        else printf("YES\n");
    }
    return 0;

}


#include<bits/stdc++.h>
#define INF     1e9
#define ld      long double
#define lli     long long int
#define PI 	    acos(-1)
#define read    freopen("in.txt","r",stdin)
#define uu		first
#define vv		second
#define write   freopen("out.txt","w",stdout)
#define pii     pair<int,int>
using namespace std;
string gd,in,str;
int n,tmp,cnt,flg,ara[30];
int main()
{
    cin>>gd>>in>>n;
    for(int i=0;i<gd.size();i++) {
        ara[ gd[i]-'a' ]=1;
    }
    while(n--) {
        flg=0;
        cin>>str;
        for(int i=0;i<str.size();i++) {
            if(in[i]=='?') {
                if( ara[ str[i]-'a' ]==0) {
                    flg=1;
                    break;
                }
            }
            else if(in[i]=='*') {
                if( ara[ str[i]-'a' ]==1) {
                    flg=1;
                    break;
                }
            }
            else {
                if(in[i]!=str[i]) {
                    flg=1;
                    break;
                }
            }

        }
        if(flg) printf("NO\n");
            else printf("YES\n");
    }
    return 0;
}


#include<bits/stdc++.h>
#define INF     1e9
#define ld      long double
#define lli     long long int
#define PI 	    acos(-1)
#define read    freopen("in.txt","r",stdin)
#define uu		first
#define vv		second
#define write   freopen("out.txt","w",stdout)
#define pii     pair<int,int>
using namespace std;
string gd,str,ask;
int q,n,t,ans,tmp,cnt,ara[1000];
int main()
{
	cin>>gd>>str>>n;
	for(int i=0;i<gd.size();i++) ara[ gd[i] - 'a' ] = 1;
	while(n--) {
		cin>>ask;
		int in=-1,fin=-1;
		ans=0;

		for(int i=0;i< max(str.size(), ask.size() );i++) {
			if( str[i]== '?') {
				if( ara[ ask[i] - 'a' ] != 1) {
					ans=2;
					break;
				}
			}
			else if( str[i] == '*' ) {
				in=i;
				break;
			}
			else {
				if( str[i] != ask[i]) {
					ans=2;
					break;
				}
			}
		}
        //cout<<in<<" "<<fin<<endl;
		if(ans==2) {
			printf("NO\n");
			continue;
		}
		else if(in==-1) {
			printf("YES\n");
			continue;
		}

		else {

			for(int i=str.size()-1 ,j=ask.size()-1; i>=0; i--,j--) {
				if( str[i]== '?') {
					if( ara[ ask[j] - 'a' ] != 1) {
						ans=2;
						break;
					}
				}
				else if( str[i] == '*' ) {
					fin=j+1;
					break;
				}
				else {
					if( str[i] != ask[j]) {
						ans=2;
						break;
					}
				}
			}
		}
        //cout<<in<<" "<<fin<<endl;
		if(ans==2 || fin==-1) {
			printf("NO\n");
			continue;
		}

		else {
			for(int i=in; i<fin;i++ ) {
				if( ara[ ask[i] - 'a' ] == 1 ) {
					ans=2;
					break;
				}
			}
		}

		if(ans==2) {
			printf("NO\n");
		}
		else printf("YES\n");
	}
	return 0;
}


#include<bits/stdc++.h>
#define INF     1e9
#define ld      long double
#define lli     long long int
#define PI 	    acos(-1)
#define read    freopen("in.txt","r",stdin)
#define uu		first
#define vv		second
#define write   freopen("out.txt","w",stdout)
#define pii     pair<int,int>
using namespace std;
string gd,in,str,baal;
int n,tmp,cnt,flg,ara[30];
int main()
{
    cin>>gd>>in>>n;
    for(int i=0;i<gd.size();i++) {
        ara[ gd[i]-'a' ]=1;
    }
    while(n--) {
        cin>>str;
        flg=0;
        if(str.size()==in.size()) {
            for(int i=0;i<str.size();i++) {
                if(in[i]=='?') {
                    if( ara[ str[i]-'a' ]==0) {
                        flg=1;
                        break;
                    }
                }
                else if(in[i]=='*') {
                    if( ara[ str[i]-'a' ]==1) {
                        flg=1;
                        break;
                    }
                }
                else {
                    if(in[i]!=str[i]) {
                        flg=1;
                        break;
                    }
                }
            }
        }
        else if(in.size()-str.size()==1) {
            /*for(int i=0;i<in.size();i++) {
                if(in[i]!='*') baal[cnt++]=in[i];
            }
            cout<<in<<" "<<baal<<" wtf"<<endl;*/
            //if(in.size()==str.size()) {
                for(int i=0,cnt=0;i<in.size();i++,cnt++) {
                    if(in[i]=='*') cnt++;
                    else if(in[i]=='?') {
                        if( ara[ str[cnt]-'a' ]==0) {
                            flg=1;
                            break;
                        }
                    }
                    else {
                        if(in[i]!=str[cnt]) {
                            flg=1;
                            break;
                        }
                    }

                }
            //}
            //else flg=1;
        }
        else flg=1;

        if(flg==1) printf("NO\n");
        else printf("YES\n");
    }
    return 0;

}


#include<bits/stdc++.h>
#define INF     1e9
#define ld      long double
#define lli     long long int
#define PI 	    acos(-1)
#define read    freopen("in.txt","r",stdin)
#define uu		first
#define vv		second
#define write   freopen("out.txt","w",stdout)
#define pii     pair<int,int>
using namespace std;
string gd,in,str,baal;
int n,tmp,cnt,flg,ara[30];
int main()
{
    cin>>gd>>in>>n;
    for(int i=0;i<gd.size();i++) {
        ara[ gd[i]-'a' ]=1;
    }
    while(n--) {
        cin>>str;
        flg=0;

        if(str.size()==in.size()) {
            for(int i=0;i<str.size();i++) {
                if(in[i]=='?') {
                    if( ara[ str[i]-'a' ]==0) {
                        flg=1;
                        break;
                    }
                }
                else if(in[i]=='*') {
                    if( ara[ str[i]-'a' ]==1) {
                        flg=1;
                        break;
                    }
                }
                else {
                    if(in[i]!=str[i]) {
                        flg=1;
                        break;
                    }
                }
            }
        }
        else if(in.size()-str.size()==1) {
           for(int i=0,cnt=0;cnt<in.size();i++,cnt++) {
                    if(in[cnt]=='*') {
                        cnt++;
                    }
                    else if(in[cnt]=='?') {
                        if( ara[ str[i]-'a' ]==0) {
                            flg=1;
                            break;
                        }
                    }
                    else {
                        if(in[cnt]!=str[i]) {
                            flg=1;
                            break;
                        }
                    }

                }

        }
        else flg=1;

        if(flg) printf("NO\n");
        else printf("YES\n");
    }
    return 0;

}


#include<bits/stdc++.h>
#define INF     1e9
#define ld      long double
#define lli     long long int
#define PI 	    acos(-1)
#define read    freopen("in.txt","r",stdin)
#define uu		first
#define vv		second
#define write   freopen("out.txt","w",stdout)
#define pii     pair<int,int>
using namespace std;
string gd,in,str;
int n,tmp,cnt,flg,ara[30];
int main()
{
    cin>>gd>>in>>n;
    for(int i=0;i<gd.size();i++) {
        ara[ gd[i]-'a' ]=1;
    }
    while(n--) {
        flg=0;
        cin>>str;
        if(in.size()==str.size()) {
            for(int i=0;i<str.size();i++) {
                if(in[i]=='?') {
                    if( ara[ str[i]-'a' ]==0) {
                        flg=1;
                        break;
                    }
                }
                else if(in[i]=='*') {
                    if( ara[ str[i]-'a' ]==1) {
                        flg=1;
                        break;
                    }
                }
                else {
                    if(in[i]!=str[i]) {
                        flg=1;
                        break;
                    }
                }

            }
        }
        else if(in.size()-str.size()==1){
            for(int i=0,j=0;j<in.size() ;i++,j++) {
                if(in[j]=='?') {
                    if( ara[ str[i]-'a' ]==0) {
                        flg=1;
                        break;
                    }
                }
                else if(in[j]=='*') {
                    j++;
                }
                else {
                    if(in[j]!=str[i]) {
                        flg=1;
                        break;
                    }
                }
            }
        }
        else flg=1;
        if(flg) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}


#include<bits/stdc++.h>
#define INF     1e9
#define ld      long double
#define lli     long long int
#define PI 	    acos(-1)
#define read    freopen("in.txt","r",stdin)
#define uu		first
#define vv		second
#define write   freopen("out.txt","w",stdout)
#define pii     pair<int,int>
using namespace std;
string gd,str,ask;
int q,n,t,ans,tmp,cnt,ara[1000];
int main()
{
	cin>>gd>>str>>n;
	for(int i=0;i<gd.size();i++) ara[ gd[i] - 'a' ] = 1;
	while(n--) {
		cin>>ask;
		int in=-1,fin=-1;
		ans=0;

		for(int i=0;i< max(str.size(), ask.size() );i++) {
			if( str[i]== '?') {
				if( ara[ ask[i] - 'a' ] != 1) {
					ans=2;
					break;
				}
			}
			else if( str[i] == '*' ) {
				in=i;
				break;
			}
			else {
				if( str[i] != ask[i]) {
					ans=2;
					break;
				}
			}
		}

		if(ans==2) {
			printf("NO\n");
			continue;
		}
		else if(in==-1) {
			printf("YES\n");
			continue;
		}
		else {

			for(int i=str.size()-1 ,j=ask.size()-1; i>=in; i--,j--) {
				if( str[i]== '?') {
					if( ara[ ask[j] - 'a' ] != 1) {
						ans=2;
						break;
					}
				}
				else if( str[i] == '*' ) {
					fin=j;
					break;
				}
				else {
					if( str[i] != ask[j]) {
						ans=2;
						break;
					}
				}
			}
		}

		if(ans==2) {
			printf("NO\n");
			continue;
		}

		else {
			for(int i=in; i<=fin;i++ ) {
				if( ara[ ask[i] - 'a' ] == 1 ) {
					ans=2;
					break;
				}
			}
		}

		if(ans==2) {
			printf("NO\n");
		}
		else printf("YES\n");
	}
	return 0;
}


#include<bits/stdc++.h>
#define INF     1e9
#define ld      long double
#define lli     long long int
#define PI 	    acos(-1)
#define read    freopen("in.txt","r",stdin)
#define uu		first
#define vv		second
#define write   freopen("out.txt","w",stdout)
#define pii     pair<int,int>
using namespace std;
string gd,str,ask;
int q,n,t,ans,tmp,cnt,ara[1000];
int main()
{
	cin>>gd>>str>>n;
	for(int i=0;i<gd.size();i++) ara[ gd[i] - 'a' ] = 1;
	while(n--) {
		cin>>ask;
		int in=-1,fin=-1;
		ans=0;

		for(int i=0;i< max(str.size(), ask.size() );i++) {
			if( str[i]== '?') {
				if( ara[ ask[i] - 'a' ] != 1) {
					ans=2;
					break;
				}
			}
			else if( str[i] == '*' ) {
				in=i;
				break;
			}
			else {
				if( str[i] != ask[i]) {
					ans=2;
					break;
				}
			}
		}
        //cout<<in<<" "<<fin<<endl;
		if(ans==2) {
			printf("NO\n");
			continue;
		}
		else if(in==-1) {
			printf("YES\n");
			continue;
		}

		else {

			for(int i=str.size()-1 ,j=ask.size()-1; i>=0; i--,j--) {
				if( str[i]== '?') {
					if( ara[ ask[j] - 'a' ] != 1) {
						ans=2;
						break;
					}
				}
				else if( str[i] == '*' ) {
					fin=j+1;
					break;
				}
				else {
					if( str[i] != ask[j]) {
						ans=2;
						break;
					}
				}
			}
		}
        //cout<<in<<" "<<fin<<endl;
		if(ans==2 || fin==-1 || in>fin) {
			printf("NO\n");
			continue;
		}

		else {
			for(int i=in; i<fin;i++ ) {
				if( ara[ ask[i] - 'a' ] == 1 ) {
					ans=2;
					break;
				}
			}
		}

		if(ans==2) {
			printf("NO\n");
		}
		else printf("YES\n");
	}
	return 0;
}


#include<bits/stdc++.h>
#define INF     1e9
#define ld      long double
#define lli     long long int
#define PI 	    acos(-1)
#define read    freopen("in.txt","r",stdin)
#define uu		first
#define vv		second
#define write   freopen("out.txt","w",stdout)
#define pii     pair<int,int>
using namespace std;
string gd,in,str,baal;
int n,tmp,cnt,flg,ara[30];
int main()
{
    cin>>gd>>in>>n;
    for(int i=0;i<gd.size();i++) {
        ara[ gd[i]-'a' ]=1;
    }
    while(n--) {
        flg=0;
        tmp=0;
        cin>>str;
        if(in.size()-str.size()==0 || in.size()-str.size()==1) {
            for(int i=0;i<str.size();i++) {
                if(in[i]=='?') {
                    if( ara[ str[i]-'a' ]==0) {
                        flg=2;
                        break;
                    }
                }
                else if(in[i]=='*') {
                    tmp=1;
                    if( ara[ str[i]-'a' ]==1) {
                        flg=1;
                        break;
                    }
                }
                else {
                    if(in[i]!=str[i]) {
                        flg=2;
                        break;
                    }
                }

            }
        }
        else flg=2;

        if(flg==1 && tmp==1) {
            cnt=0;
            for(int i=0;i<in.size();i++) {
                if(in[i]!='*') baal[cnt++]=in[i];
            }

            for(int i=0;i<str.size();i++) {
                if(baal[i]=='?') {
                    if( ara[ str[i]-'a' ]==0) {
                        flg=2;
                        break;
                    }
                }
                else {
                    if(baal[i]!=str[i]) {
                        flg=2;
                        break;
                    }
                }

            }
        }

        if(flg==2) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}


#include<bits/stdc++.h>
#define INF     1e9
#define ld      long double
#define lli     long long int
#define PI 	    acos(-1)
#define read    freopen("in.txt","r",stdin)
#define uu		first
#define vv		second
#define write   freopen("out.txt","w",stdout)
#define pii     pair<int,int>
using namespace std;
string gd,str,ask;
int q,n,t,ans,tmp,cnt,ara[1000];
int main()
{
	cin>>gd>>str>>n;
	for(int i=0;i<gd.size();i++) ara[ gd[i] - 'a' ] = 1;
	while(n--) {
		cin>>ask;
		int in=-1,fin=-1;
		ans=0;

		for(int i=0;i< max(str.size(), ask.size() );i++) {
			if( str[i]== '?') {
				if( ara[ ask[i] - 'a' ] != 1) {
					ans=2;
					break;
				}
			}
			else if( str[i] == '*' ) {
				in=i;
				break;
			}
			else {
				if( str[i] != ask[i]) {
					ans=2;
					break;
				}
			}
		}

		if(ans==2) {
			printf("NO\n");
			continue;
		}
		else if(in==-1) {
			printf("YES\n");
			continue;
		}
		else {

			for(int i=str.size()-1 ,j=ask.size()-1; i>=0; i--,j--) {
				if( str[i]== '?') {
					if( ara[ ask[j] - 'a' ] != 1) {
						ans=2;
						break;
					}
				}
				else if( str[i] == '*' ) {
					fin=j;
					break;
				}
				else {
					if( str[i] != ask[j]) {
						ans=2;
						break;
					}
				}
			}
		}

		if(ans==2 || fin==-1) {
			printf("NO\n");
			continue;
		}

		else {
			for(int i=in; i<=fin;i++ ) {
				if( ara[ ask[i] - 'a' ] == 1 ) {
					ans=2;
					break;
				}
			}
		}

		if(ans==2) {
			printf("NO\n");
		}
		else printf("YES\n");
	}
	return 0;
}


#include <bits/stdc++.h>
#define maxn 100010
#define inf 0x3f3f3f3f
#define REP(i,x,y) for(int i=x;i<(y);i++)
#define RREP(i,x,y) for(int i=x;i>(y);i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
string s,good;
map<char ,bool>ma;
int main()
{
    //ios::sync_with_stdio(false);
    cin>>good;
    REP(i,0,good.length())
        ma[good[i]]=1;
    cin>>s;
    int pos=0;
    REP(i,0,s.length())
        if(s[i]=='*') {pos=i;break;}
    int suf=0,pre=0;
    REP(i,0,s.length()){
        if(i<pos) pre++;
        else if(i>pos) suf++;
    }
    int q;
    scanf("%d",&q);
    while(q--){
        string t;cin>>t;int flag=1;
        int sub=t.length()-suf-pre;
        int j=0;
        REP(i,0,s.length()){
            if(s[i]==t[j]) j++;
            else if(s[i]=='?'){
                if(ma[t[j]]) j++;
                else {flag=0;break;}
            }
            else if(s[i]=='*'){
                if(sub>=0){
                    int ed=j+sub;
                    while(j<=ed){
                        if(ma.count(t[j])==0&&((t[j]>='a'&&t[j]<='z')||t[j]==' ')) j++;
                        else {flag=0;break;}
                    }
                    if(flag==0) break;
                }
                else{
                    i+=(-sub);
                    i--;
                }
            }
            else {flag=0;break;}
        }
        if(flag) puts("YES");
        else puts("NO");
    }
}


#include <bits/stdc++.h>
#define REP(i,x,y) for(int i=x;i<(y);i++)

using namespace std;
typedef long long ll;
map<char,int>ma;
int main()
{
    string good;
    cin >> good;
    for (int i = 0; i<good.length();i++){
        ma[good[i]] = 1;
    }
    string s;
    cin >> s;
    int num = 0;
    for (int i = 0; i<s.length();i++) if (s[i] == '*') num++;
    int q;
    cin >> q;
    while(q--)
    {
        string t;
        cin >> t;
        int flag = 1;
        if (t.length()==s.length())
        {
            for (int i = 0; i<t.length() ;i++)
            {
                if (s[i] == '?'&&ma[t[i]]==0) flag = 0;
                if (s[i]!='?'&&s[i]!='*'&& s[i]!=t[i]) flag = 0;
                if (s[i]=='*' && ma[t[i]]==1) flag = 0;
            }
            if(!flag)
                puts("NO");
            else puts("YES");
        }
        else if (num==1&&t.length()+1==s.length()){
            int j = 0;
            for (int i = 0;i<t.length(); i++)
            {
                if (s[j]=='?'&& ma[t[i]]==0) flag = 0;
                if (s[j]=='*') {j++;}
                if (s[j]!='?'&&s[j]!='*' && s[j]!=t[i]) flag = 0;
                j++;
            }
            if(flag == 0)
                puts("NO");
            else puts("YES");
        }
        else if (t.length() > s.length() && num == 1)
        {
            int sub = t.length() - s.length();
            int j = 0;
            for (int i = 0;i<t.length(); i++)
            {
                if (s[j]=='*') {
                    for (int z = 1;z<=sub;i++,z++){
                        if (ma.count(t[i])==1) flag =0;
                        }
                    j++;
                }
                if (i+1 >= t.length()) break;
                if (s[j]=='?'&& ma[t[i]]==0) flag = 0;
                if (s[j]!='?'&&s[j]!='*' && s[j]!=t[i]) flag = 0;
                j++;
            }
            if(flag == 0)
                puts("NO");
            else puts("YES");
        }
        else{
            puts("NO");
        }
    }
}


#include <bits/stdc++.h>
#define REP(i,x,y) for(int i=x;i<(y);i++)

using namespace std;
typedef long long ll;
map<char,int>ma;
int main()
{
    string good;
    cin >> good;
    for (int i = 0; i<good.length();i++){
        ma[good[i]] = 1;
    }
    string s;
    cin >> s;
    int num = 0;
    for (int i = 0; i<s.length();i++) if (s[i] == '*') num++;
    int q;
    cin >> q;
    while(q--)
    {
        string t;
        cin >> t;
        int flag = 1;
        if (t.length()==s.length())
        {
            for (int i = 0; i<t.length() ;i++)
            {
                if (s[i] == '?'&&ma[t[i]]==0) flag = 0;
                if (s[i]!='?'&&s[i]!='*'&& s[i]!=t[i]) flag = 0;
                if (s[i]=='*' && ma[t[i]]==1) flag = 0;
            }
            if(!flag)
                puts("NO");
            else puts("YES");
        }
        else if (num==1&&t.length()+1==s.length()){
            int j = 0;
            for (int i = 0;i<t.length(); i++)
            {
                if (s[j]=='?'&& ma[t[i]]==0) flag = 0;
                if (s[j]=='*') {j++;}
                if (s[j]!='?'&&s[j]!='*' && s[j]!=t[i]) flag = 0;
                j++;
            }
            if(flag == 0)
                puts("NO");
            else puts("YES");
        }
        else if (t.length() > s.length() && num == 1)
        {
            int sub = t.length() - s.length();
            int j = 0;
            for (int i = 0;i<t.length(); i++)
            {
                if (s[j]=='*') {
                    for (int z = 1;z<=sub;i++,z++){
                        if (ma,count(t[i])==1) flag =0;
                        }
                    j++;
                }
                if (i+1 >= t.length()) break;
                if (s[j]=='?'&& ma[t[i]]==0) flag = 0;
                if (s[j]!='?'&&s[j]!='*' && s[j]!=t[i]) flag = 0;
                j++;
            }
            if(flag == 0)
                puts("NO");
            else puts("YES");
        }
        else{
            puts("NO");
        }
    }
}


#include <bits/stdc++.h>
#define REP(i,x,y) for(int i=x;i<(y);i++)

using namespace std;
typedef long long ll;
map<char,bool>ma;
int main()
{
    string good;
    cin >> good;
    for (int i = 0; i<good.length();i++){
        ma[good[i]] = 1;
    }
    string s;
    cin >> s;
    int num = 0;
    for (int i = 0; i<s.length();i++)
        if (s[i] == '*') num++;
    int q;
    cin >> q;
    while(q--)
    {
        string t;
        cin >> t;
        int flag = 1;
        if (t.length()==s.length())
        {
            for (int i = 0; i<t.length() ;i++)
            {
                if (s[i] == '?'&&ma[t[i]]==0) flag = 0;
                if (s[i]!='?'&&s[i]!='*'&& s[i]!=t[i]) flag = 0;
                if (s[i]=='*' && ma[t[i]]==1) flag = 0;
            }
            if(!flag)
                puts("NO");
            else puts("YES");
        }
        else if (num==1&&t.length()+1==s.length()){
            int j = 0;
            for (int i = 0;i<t.length(); i++)
            {
                if (s[j]=='?'&& ma[t[i]]==0) flag = 0;
                if (s[j]=='*') {j++;}
                if (s[j]!='?'&&s[j]!='*' && s[j]!=t[i]) flag = 0;
                j++;
            }
            if(flag == 0)
                puts("NO");
            else puts("YES");
        }
        else if (t.length() > s.length() && num == 1)
        {
            int sub = t.length() - s.length();
            int j = 0;
            for (int i = 0;i<t.length(); i++)
            {
                if (s[j]=='*') {
                    for (int z = 1;z<=sub;i++,z++){
                        if (ok[ma[i]]==1) flag =0;
                        }
                    j++;
                }
                if (i+1 >= t.length()) break;
                if (s[j]=='?'&& ok[t[i]-'a']==0) flag = 0;
                if (s[j]!='?'&&s[j]!='*' && s[j]!=t[i]) flag = 0;
                j++;
            }
            if(flag == 0)
                puts("NO");
            else puts("YES");
        }
        else{
            puts("NO");
        }
    }
}


#include <bits/stdc++.h>
#define maxn 100010
#define inf 0x3f3f3f3f
#define REP(i,x,y) for(int i=x;i<(y);i++)
#define RREP(i,x,y) for(int i=x;i>(y);i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
string s,good;
map<char ,bool>ma;
int main()
{
    //ios::sync_with_stdio(false);
    cin>>good;
    REP(i,0,good.length())
        ma[good[i]]=1;
    cin>>s;
    int pos=0;
    REP(i,0,s.length()){
        if(s[i]=='*') {pos=i;break;}
    }
    int q;
    scanf("%d",&q);
    while(q--){
        string t;cin>>t;int flag=1;
        int sub=t.length()-s.length();
        int j=0;
        REP(i,0,t.length()){
            if(s[i]==t[j]) j++;
            else if(s[i]=='?'){
                if(ma[t[j]]) j++;
                else {flag=0;break;}
            }
            else if(s[i]=='*'){
                int ed=j+sub;
                while(j<ed){
                    if(ma.count(t[j])==0&&((t[j]>='a'&&t[j]<='z')||t[j]==' ')) j++;
                    else {flag=0;break;}
                }
                if(flag==0) break;
                j-=1;
            }
            else {flag=0;break;}
        }
        if(flag) puts("YES");
        else puts("NO");
    }
}


#include <bits/stdc++.h>
#define maxn 100010
#define inf 0x3f3f3f3f
#define REP(i,x,y) for(int i=x;i<(y);i++)
#define RREP(i,x,y) for(int i=x;i>(y);i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
string s,good;
map<char ,bool>ma;
int main()
{
    //ios::sync_with_stdio(false);
    cin>>good;
    REP(i,0,good.length())
        ma[good[i]]=1;
    cin>>s;
    int pos=0;
    REP(i,0,s.length())
        if(s[i]=='*') {pos=i;break;}
    int suf=0,pre=0;
    REP(i,0,s.length()){
        if(i<pos) pre++;
        else if(i>pos) suf++;
    }
    int q;
    scanf("%d",&q);
    while(q--){
        string t;cin>>t;int flag=1;
        int sub=t.length()-suf-pre;
        int j=0;
        REP(i,0,s.length()){
            if(s[i]==t[j]) j++;
            else if(s[i]=='?'){
                if(ma[t[j]]) j++;
                else {flag=0;break;}
            }
            else if(s[i]=='*'){
                if(sub==0) continue;
                else if(sub>0){
                    int ed=j+sub;
                    while(j<=ed){
                        if(ma.count(t[j])==0&&((t[j]>='a'&&t[j]<='z')||t[j]==' ')) j++;
                        else {flag=0;break;}
                    }
                    if(flag==0) break;
                }
                else{
                    i+=(-sub);
                    i--;
                }
            }
            else {flag=0;break;}
        }
        if(flag) puts("YES");
        else puts("NO");
    }
}


#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
int ma[35];
int main()
{
    string good;
    cin >> good;
    for (int i = 0; i<good.length();i++){
        ma[g[i]-'a'] = 1;
    }
    string s;
    cin >> s;
    int num = 0;
    for (int i = 0; i<s.length();i++) if (s[i] == '*') num++;
    int q;cin >> q;
    for (int i = 1; i<=q; i++)
    {
        string t;
        cin >> t;
        int flag = 1;
        if (t.length()==s.length())
        {
            for (int i = 0; i<s.length() ;i++)
            {
                if (s[i]=='*' && ok[t[i]-'a']==1) flag = 0;
                if (s[i] == '?'&&ok[t[i]-'a']==0) flag = 0;
                if (s[i]!='?'&&s[i]!='*'&& s[i]!=t[i]) flag = 0;
            }
            if(flag)
                puts("YES");
            else puts("NO");
        }
        else if (t.length()+1==s.length() && num == 1)
        {
            int j = 0;
            for (int i = 0;i<t.length(); i++)
            {
                if (s[j]=='*') {j++;}
                if (s[j]=='?'&& ok[t[i]-'a']==0) flag = 0;
                if (s[j]!='?'&&s[j]!='*' && s[j]!=t[i]) flag = 0;
                j++;
            }
            if(flag)
                puts("YES");
            else puts("NO");
        }
        else if (t.length() > s.length() && num == 1)
        {
            int det = t.length() - s.length();
            int j = 0;
            for (int i = 0;i<t.length(); i++)
            {
                if (s[j]=='*') {
                    for (int z = 1;z<=det;i++,z++){
                        if (ok[t[i]-'a']==1) flag =0;
                        }
                    j++;
                }
                if (i+1 >= t.length()) break;
                if (s[j]!='?'&&s[j]!='*' && s[j]!=t[i]) flag = 0;
                if (s[j]=='?'&& ok[t[i]-'a']==0) flag = 0;
                j++;
            }
            if(flag == 0)
                puts("NO");
            else puts("YES");
        }
        else
            puts("NO");
    }
}


#include <bits/stdc++.h>
#define maxn 100010
#define inf 0x3f3f3f3f
#define REP(i,x,y) for(int i=x;i<(y);i++)
#define RREP(i,x,y) for(int i=x;i>(y);i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
string s,good;
map<char ,bool>ma;
int main()
{
    //ios::sync_with_stdio(false);
    cin>>good;
    REP(i,0,good.length())
        ma[good[i]]=1;
    cin>>s;
    int pos=0;
    REP(i,0,s.length()){
        if(s[i]=='*') {pos=i;break;}
    }
    int q;
    scanf("%d",&q);
    while(q--){
        string t;cin>>t;int flag=1;
        int sub=t.length()-s.length();
        int j=0;
        REP(i,0,t.length()){
            if(s[i]==t[j]) j++;
            else if(s[i]=='?'){
                if(ma[t[j]]) j++;
                else {flag=0;break;}
            }
            else if(s[i]=='*'){
                if(sub>=0){
                    int ed=j+sub;
                    while(j<ed){
                        if(ma.count(t[j])==0&&((t[j]>='a'&&t[j]<='z')||t[j]==' ')) j++;
                        else {flag=0;break;}
                    }
                    if(flag==0) break;
                }
                else {
                    i+=(-sub);
                    i-=1;
                }
            }
            else {flag=0;break;}
        }
        if(flag) puts("YES");
        else puts("NO");
    }
}


#include <bits/stdc++.h>
#define maxn 100010
#define inf 0x3f3f3f3f
#define REP(i,x,y) for(int i=x;i<(y);i++)
#define RREP(i,x,y) for(int i=x;i>(y);i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
string s,good;
map<char ,bool>ma;
int main()
{
    //ios::sync_with_stdio(false);
    cin>>good;
    REP(i,0,good.length())
        ma[good[i]]=1;
    cin>>s;
    int pos=0;
    REP(i,0,s.length()){
        if(s[i]=='*') {pos=i;break;}
    }
    int q;
    scanf("%d",&q);
    while(q--){
        string t;cin>>t;int flag=1;
        int sub=t.length()-s.length();
        int j=0;
        REP(i,0,s.length()){
            if(s[i]==t[j]) j++;
            else if(s[i]=='?'){
                if(ma[t[j]]) j++;
                else {flag=0;break;}
            }
            else if(s[i]=='*'){
                if(sub>=0){
                    int ed=j+sub;
                    while(j<=ed){
                        if(ma.count(t[j])==0&&((t[j]>='a'&&t[j]<='z')||t[j]==' ')) j++;
                        else {flag=0;break;}
                    }
                    if(flag==0) break;
                }
                else {
                    i+=(-sub);
                    i-=1;
                }
            }
            else {flag=0;break;}
        }
        if(flag) puts("YES");
        else puts("NO");
    }
}


#include <bits/stdc++.h>
#define maxn 100010
#define inf 0x3f3f3f3f
#define REP(i,x,y) for(int i=x;i<(y);i++)
#define RREP(i,x,y) for(int i=x;i>(y);i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
string s,good;
map<char ,bool>ma;
int main()
{
    //ios::sync_with_stdio(false);
    cin>>good;
    REP(i,0,good.length())
        ma[good[i]]=1;
    cin>>s;
    int pos=0;
    REP(i,0,s.length()){
        if(s[i]=='*') {pos=i;break;}
    }
    int q;
    scanf("%d",&q);
    while(q--){
        string t;cin>>t;int flag=1;
        int sub=t.length()-s.length();
        int j=0;
        REP(i,0,s.length()){
            if(s[i]==t[j]) j++;
            else if(s[i]=='?'){
                if(ma[t[j]]) j++;
                else {flag=0;break;}
            }
            else if(s[i]=='*'){
                if(sub>=0){
                    int ed=j+sub;
                    while(j<=ed){
                        if(ma.count(t[j])==0&&((t[j]>='a'&&t[j]<='z')||t[j]==' ')) j++;
                        else {flag=0;break;}
                    }
                    if(flag==0) break;
                }
                else
                    i+=(-sub);
            }
            else {flag=0;break;}
        }
        if(flag) puts("YES");
        else puts("NO");
    }
}


#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
int ma[35];
int main()
{
    string good;
    cin >> good;
    for (int i = 0; i<good.length();i++){
        ma[good[i]-'a'] = 1;
    }
    string s;
    cin >> s;
    int num = 0;
    for (int i = 0; i<s.length();i++) if (s[i] == '*') num++;
    int q;cin >> q;
    for (int i = 1; i<=q; i++)
    {
        string t;
        cin >> t;
        int flag = 1;
        if (t.length()==s.length())
        {
            for (int i = 0; i<s.length() ;i++)
            {
                if (s[i]=='*' && ma[t[i]-'a']==1) flag = 0;
                if (s[i] == '?'&&ma[t[i]-'a']==0) flag = 0;
                if (s[i]!='?'&&s[i]!='*'&& s[i]!=t[i]) flag = 0;
            }
            if(flag)
                puts("YES");
            else puts("NO");
        }
        else if (t.length()+1==s.length() && num == 1)
        {
            int j = 0;
            for (int i = 0;i<t.length(); i++)
            {
                if (s[j]=='*') {j++;}
                if (s[j]=='?'&& ma[t[i]-'a']==0) flag = 0;
                if (s[j]!='?'&&s[j]!='*' && s[j]!=t[i]) flag = 0;
                j++;
            }
            if(flag)
                puts("YES");
            else puts("NO");
        }
        else if (t.length() > s.length() && num == 1)
        {
            int det = t.length() - s.length();
            int j = 0;
            for (int i = 0;i<t.length(); i++)
            {
                if (s[j]=='*') {
                    for (int z = 1;z<=det;i++,z++){
                        if (ma[t[i]-'a']==1) flag =0;
                        }
                    j++;
                }
                if (i+1 >= t.length()) break;
                if (s[j]!='?'&&s[j]!='*' && s[j]!=t[i]) flag = 0;
                if (s[j]=='?'&& ma[t[i]-'a']==0) flag = 0;
                j++;
            }
            if(flag == 0)
                puts("NO");
            else puts("YES");
        }
        else
            puts("NO");
    }
}


#include <bits/stdc++.h>
#define maxn 100010
#define inf 0x3f3f3f3f
#define REP(i,x,y) for(int i=x;i<(y);i++)
#define RREP(i,x,y) for(int i=x;i>(y);i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
string s,good;
map<char ,bool>ma;
int main()
{
    //ios::sync_with_stdio(false);
    cin>>good;
    REP(i,0,good.length())
        ma[good[i]]=1;
    cin>>s;
    int pos=-1;
    REP(i,0,s.length())
        if(s[i]=='*') {pos=i;break;}
    int suf=0,pre=0;
    REP(i,0,s.length()){
        if(i<pos) pre++;
        else if(i>pos) suf++;
    }
    int q;
    scanf("%d",&q);
    while(q--){
        string t;cin>>t;int flag=1;
        if(pos==-1&&t.length()>s.length()) {puts("NO");continue;}
        int sub=t.length()-suf-pre;

        int j=0;
        REP(i,0,s.length()){
            if(s[i]==t[j]) j++;
            else if(s[i]=='?'){
                if(ma[t[j]]) j++;
                else {flag=0;break;}
            }
            else if(s[i]=='*'){
                if(sub==0) continue;
                else if(sub>0){
                    int ed=j+sub;
                    while(j<ed){
                        if(ma.count(t[j])==0&&((t[j]>='a'&&t[j]<='z')||t[j]==' ')) j++;
                        else {flag=0;break;}
                    }
                    if(flag==0) break;
                }
                else{
                    i+=(-sub);
                    i--;
                }
            }
            else {flag=0;break;}
        }
        if(flag) puts("YES");
        else puts("NO");
    }
}