#include <stdio.h>

int N;
int a = -1;
int prev_a = -1;
int count = 0;
int answer = 0;

int C = 0;
int value[200];
int total[200];
int lazy_days[200];

int main()
{
	scanf(" %d",&N);

	// -----------------------

	for(int i=0; i<N; i++)
	{
		prev_a = a;

		scanf(" %d", &a);

		if(prev_a != a)
		{
			if(prev_a != -1)
			{
				value[C] = prev_a;
				total[C] = count;
				C++;
			}
			count = 1;
		}
		else
		{
			count++;
		}
	}
	value[C] = a;
	total[C] = count;
	C++;

	//------------------------

	for(int i=0;i<C;i++)
	{
		if(value[i]==0)
		{
			lazy_days[i] = total[i];
		}
		if(value[i]==1||value[i]==2)
		{
			lazy_days[i] = total[i]/2;
		}
	}

	for(int i=1;i<C-1;i++)
	{
		if(value[i]==3)
		{
			if(value[i-1] != value[i+1] && total[i]%2)
			{
				lazy_days[i] = 1;
			}
			else if(value[i-1] == value[i+1] && total[i]%2==0)
			{
				lazy_days[i] = 1;
			}
		}
	}

	for(int i=1;i<C-1;i++)
	{
		if(value[i]==3)
		{
			if(value[i-1]==0 || value[i+1]==0)
			{
				lazy_days[i] = 0;
				continue;
			}
			if(total[i-1]%2==0)
			{
				lazy_days[i] = 0;
			}
			else if(total[i+1]%2==0)
			{
				lazy_days[i] = 0;
				i+=2;
			}
		}
	}

	// --------------

	answer = 0;
	for(int i=0;i<C;i++)
	{
		answer += lazy_days[i];
	}

	printf("%d",answer);
}


#include<iostream>
using namespace std;
int str[1000], sto[1000];
char c[1000][1000];
int main(){
	int x,y,b=0,m=0,sum=0;
	cin>>x>>y;

	for(int i=1;i<=x;++i){
		for(int j=1;j<=y;++j){
			cin>>c[i][j];
			if(c[i][j]=='*'){
				b++;
				str[j]++;
				sto[i]++;
			}
		}
	}
	for(int i=1;i<=x;++i){
		if(m==1) break;
		for(int j=1;j<=y;++j){
			if(c[i][j]=='*') sum=str[j]+sto[i]-1;
			else sum=str[j]+sto[i];
			if(sum==b){
				cout<<"YES"<<endl<<i<<" "<<j;
				m=1;
				break;
			}
		}
	}
	if(m==0) cout<<"NO";
	return 0;
}


#include<iostream>
using namespace std;
int str[1001], sto[1001];
char c[1001][1001];
int main(){
	int x,y,b=0,m=0,sum=0;
	cin>>x>>y;

	for(int i=1;i<=x;++i){
		for(int j=1;j<=y;++j){
			cin>>c[i][j];
			if(c[i][j]=='*'){
				b++;
				str[j]++;
				sto[i]++;
			}
		}
	}
	for(int i=1;i<=x;++i){
		if(m==1) break;
		for(int j=1;j<=y;++j){
			if(c[i][j]=='*') sum=str[j]+sto[i]-1;
			else sum=str[j]+sto[i];
			if(sum==b){
				cout<<"YES"<<endl<<i<<" "<<j;
				m=1;
				break;
			}
		}
	}
	if(m==0) cout<<"NO";
	return 0;
}


#include<iostream>
using namespace std;
int str[1000], sto[1000];
int main(){
	int x,y,b=0,m=0,sum=0;
	cin>>x>>y;
	char c[1000][1000];
	for(int i=1;i<=x;++i){
		for(int j=1;j<=y;++j){
			cin>>c[i][j];
			if(c[i][j]=='*'){
				b++;
				str[j]++;
				sto[i]++;
			}
		}
	}
	for(int i=1;i<=x;++i){
		if(m==1) break;
		for(int j=1;j<=y;++j){
			if(c[i][j]=='*') sum=str[j]+sto[i]-1;
			else sum=str[j]+sto[i];
			if(sum==b){
				cout<<"YES"<<endl<<i<<" "<<j;
				m=1;
				break;
			}
		}
	}
	if(m==0) cout<<"NO";
	return 0;
}


#include<iostream>
using namespace std;
int str[1000], sto[1000];
int main(){
	int x,y,b=0,m=0;
	cin>>x>>y;
	char c;
	for(int i=1;i<=x;++i){
		for(int j=1;j<=y;++j){
			cin>>c;
			if(c=='*'){
				b++;
				str[j]++;
				sto[i]++;
				//cout<<"dfds"<<b<<endl;
			}
		}
	}
	for(int i=1;i<=x;++i){
		if(m==1) break;
		for(int j=1;j<=y;++j){
		//	cout<<i<<" "<<j<<" "<<str[j]+sto[i]<<endl;
			if((str[j]+sto[i]) - 1==b){
				cout<<"YES"<<endl<<i<<" "<<j;
				m=1;
				break;
			}
		}
	}
	if(m==0) cout<<"NO";
	return 0;
}


#include<iostream>
using namespace std;
int str[10000], sto[1000		0];
int main(){
	int x,y,b=0,m=0;
	cin>>x>>y;
	char c;
	for(int i=1;i<=x;++i){
		for(int j=1;j<=y;++j){
			cin>>c;
			if(c=='*'){
				b++;
				str[j]++;
				sto[i]++;
				//cout<<"dfds"<<b<<endl;
			}
		}
	}
	for(int i=1;i<=x;++i){
		if(m==1) break;
		for(int j=1;j<=y;++j){
		//	cout<<i<<" "<<j<<" "<<str[j]+sto[i]<<endl;
			if((str[j]+sto[i]) - 1==b){
				cout<<"YES"<<endl<<i<<" "<<j;
				m=1;
				break;
			}
		}
	}
	if(m==0) cout<<"NO";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main(int argc, char const *argv[])
{
	//freopen("C:\\Users\\tiger\\Desktop\\b.txt", "r", stdin);
	char _a[100010];
    while( cin>>_a )
    {
    	bool isgood[300];
    	memset(isgood, false, sizeof(isgood));
    	int lena = strlen(_a);
    	for (int i = 0; i < lena ; ++i)
    	{
    		isgood[_a[i]] = true;
    	}
    	char a[100010];
    	cin>>a;
    	int len_a = strlen(a);

    	int t;
    	cin>>t;
    	while ( t-- )
    	{
    		char str[100010];
    		cin>>str;
    		int len_str = strlen(str);
    		int number_star;
			if ( len_str < len_a )
			{
				if ( len_a - len_str > 1 )
				{
					cout<<"NO"<<endl;
					continue;
				}
				else{
					number_star = 1;
				}
			}
			else{
				number_star = len_str - len_a + 1;
			}

    		int RET = 1;
    		for (int i = 0, j = 0; i < len_a && j < len_str; ++i, ++j)
    		{
    			if ( a[i] == str[j] )
    			{
    				continue;
    			}
    			else{
    				if ( a[i] == '?' )
    				{
    					if (  isgood[str[j]] == true )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else if ( a[i] == '*')
    				{
    					i++;
    					int flag = 1;
    					if ( i == len_a )
    					{
    						for (int cnt = 0 ; cnt < number_star; ++cnt, j++)
    						{
    							if ( isgood[str[j]] == false )
    							{
    								continue;
    							}
    							else{
    								flag = 0;
    								break;
    							}
    						}
    					}
    					else{
	    					for(int cnt = 0; cnt < number_star; ++cnt, ++j)
	    					{
	    						if ( isgood[str[j]] == false )
	    						{
	    							continue;
	    						}
	    						else{
	    							flag = 0;
	    							break;
	    						}
	    					}
	    				}
    					if ( flag )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else{
    					RET = 0;
    					break;
    				}
    			}
    		}
    		if ( RET )
    		{
    			cout<<"YES"<<'\n';
			}
			else{
				cout<<"NO"<<'\n';
			}
    	}
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main(int argc, char const *argv[])
{
	//freopen("C:\\Users\\tiger\\Desktop\\b.txt", "r", stdin);
	char _a[100010];
    while( cin>>_a )
    {
    	bool isgood[300];
    	memset(isgood, false, sizeof(isgood));
    	int lena = strlen(_a);
    	for (int i = 0; i < lena ; ++i)
    	{
    		isgood[_a[i]] = true;
    	}
    	char a[100010];
    	cin>>a;
    	int len_a = strlen(a);
    	int t;
    	cin>>t;
    	while ( t-- )
    	{
    		char str[100010];
    		cin>>str;
    		int len_str = strlen(str);
    		int number_star;
    		if ( len_str < len_a )
    		{
    			if ( len_a - len_str > 1 )
    			{
    				cout<<"NO"<<endl;
    				continue;
    			}
    			else{
    				number_star = 1;
    			}
    		}
    		else{
    			number_star = len_str - len_a + 1;
    		}
    		int RET = 1;
    		for (int i = 0, j = 0; i < len_a && j < len_str; ++i, ++j)
    		{
    			if ( a[i] == str[j] )
    			{
    				continue;
    			}
    			else{
    				if ( a[i] == '?' )
    				{
    					if (  isgood[str[j]] == true )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else if ( a[i] == '*')
    				{
    					int flag = 1;
    					if ( a[i+1] == str[j] )
    					{
    						flag = 1;
    						i++;
    					}
    					else{
	    					for( int cnt = 0;cnt < number_star && a[i]!=str[j] && j < len_str; j++)
	    					{
	    						if ( isgood[str[j]] == false )
	    						{
	    							continue;
	    						}
	    						else{
	    							flag = 0;
	    							break;
	    						}
	    					}
	    				}
    					if ( flag )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else{
    					RET = 0;
    					break;
    				}
    			}
    		}
    		if ( RET )
    		{
    			cout<<"YES"<<'\n';
			}
			else{
				cout<<"NO"<<'\n';
			}
    	}
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main(int argc, char const *argv[])
{
	//freopen("C:\\Users\\tiger\\Desktop\\b.txt", "r", stdin);
	char _a[100010];
    while( cin>>_a )
    {
    	bool isgood[400];
    	memset(isgood, false, sizeof(isgood));
    	int lena = strlen(_a);
    	for (int i = 0; i < lena ; ++i)
    	{
    		isgood[_a[i]] = true;
    	}
    	char a[100010];
    	cin>>a;
    	int len_a = strlen(a);

    	int t;
    	cin>>t;
    	while ( t-- )
    	{
    		char str[100010];
    		memset(str, '\0', sizeof(str));
    		cin>>str;
    		int len_str = strlen(str);
    		int number_star;
			if ( len_str < len_a )
			{
				if ( len_a - len_str > 1 )
				{
					cout<<"NO"<<endl;
					continue;
				}
				else{
					number_star = 1;
				}
			}
			else{
				number_star = len_str - len_a + 1;
			}
    		int cnt = 0;
    		int RET = 1;
    		for (int i = 0, j = 0; i < len_a && j < len_str; ++i, ++j)
    		{
    			if ( a[i] == str[j] )
    			{
    				continue;
    			}
    			else{
    				if ( a[i] == '?' )
    				{
    					if (  isgood[str[j]] == true )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else if ( a[i] == '*' )
    				{
    					cnt++;
    					if ( cnt > 1 )
    					{
    						RET = 0;
    						break;
    					}
    					int flag = 1;
    					for(int cnt = 0; cnt < number_star; ++cnt, ++j)
    					{
    						if ( isgood[str[j]] == false )
    						{
    							continue;
    						}
    						else{
    							flag = 0;
    							break;
    						}
    					}
    					--j;
    					if ( flag )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else{
    					RET = 0;
    					break;
    				}
    			}
    		}
    		if ( RET )
    		{
    			cout<<"YES"<<'\n';
			}
			else{
				cout<<"NO"<<'\n';
			}
    	}
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main(int argc, char const *argv[])
{
	//freopen("C:\\Users\\tiger\\Desktop\\b.txt", "r", stdin);
	char _a[100010];
    while( cin>>_a )
    {
    	bool isgood[400];
    	memset(isgood, false, sizeof(isgood));
    	int lena = strlen(_a);
    	for (int i = 0; i < lena ; ++i)
    	{
    		isgood[_a[i]] = true;
    	}
    	char a[100010];
    	cin>>a;
    	int len_a = strlen(a);

    	int t;
    	cin>>t;
    	while ( t-- )
    	{
    		char str[100010];
    		memset(str, '\0', sizeof(str));
    		cin>>str;
    		int len_str = strlen(str);
    		int number_star;
			if ( len_str < len_a )
			{
				if ( len_a - len_str > 1 )
				{
					cout<<"NO"<<endl;
					continue;
				}
				else{
					number_star = 1;
				}
			}
			else{
				number_star = len_str - len_a + 1;
			}

    		int RET = 1;
    		for (int i = 0, j = 0; i < len_a ; ++i, ++j)
    		{
    			if ( a[i] == str[j] )
    			{
    				continue;
    			}
    			else{
    				if ( a[i] == '?' )
    				{
    					if (  isgood[str[j]] == true )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else if ( a[i] == '*' )
    				{
    					i++;
    					int flag = 1;
    					if ( i == len_a )
    					{
    						for (int cnt = 0 ; cnt < number_star; ++cnt, j++)
    						{
    							if ( isgood[str[j]] == false )
    							{
    								continue;
    							}
    							else{
    								flag = 0;
    								break;
    							}
    						}
    					}
    					else{
	    					for(int cnt = 0; cnt < number_star; ++cnt, ++j)
	    					{
	    						if ( isgood[str[j]] == false )
	    						{
	    							continue;
	    						}
	    						else{
	    							flag = 0;
	    							break;
	    						}
	    					}
	    				}
    					if ( flag )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else{
    					RET = 0;
    					break;
    				}
    			}
    		}
    		if ( RET )
    		{
    			cout<<"YES"<<'\n';
			}
			else{
				cout<<"NO"<<'\n';
			}
    	}
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main(int argc, char const *argv[])
{
	//freopen("C:\\Users\\tiger\\Desktop\\b.txt", "r", stdin);
	char a[100010];
    while( cin>>a )
    {
    	bool isgood[300];
    	memset(isgood, false, sizeof(isgood));
    	int lena = strlen(a);
    	for (int i = 0; i < lena ; ++i)
    	{
    		isgood[a[i]] = true;
    	}
    	char _a[100010];
    	cin>>_a;
    	int len_a = strlen(_a);
    	int t;
    	cin>>t;
    	while ( t-- )
    	{
    		char str[100010];
    		cin>>str;
    		int len_str = strlen(str);
    		int RET = 1;
    		for (int i = 0, j = 0; i < len_a && j < len_str; ++i, ++j)
    		{
    			if ( _a[i] == str[j] )
    			{
    				continue;
    			}
    			else{
    				if ( _a[i] == '?' )
    				{
    					if (  isgood[str[j]] == true )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else if ( _a[i] == '*')
    				{
    					int flag = 1;
    					if ( a[i+1] == str[j] )
    					{
    						flag = 1;
    					}
    					else{
	    					for( ;a[i]!=str[j] && j < len_str; j++)
	    					{
	    						if ( isgood[str[j]] == false )
	    						{
	    							continue;
	    						}
	    						else{
	    							flag = 0;
	    							break;
	    						}
	    					}
	    				}
    					if ( flag )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else{
    					RET = 0;
    					break;
    				}
    			}
    		}
    		if ( RET )
    		{
    			cout<<"YES"<<'\n';
			}
			else{
				cout<<"NO"<<'\n';
			}
    	}
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main(int argc, char const *argv[])
{
	//freopen("C:\\Users\\tiger\\Desktop\\b.txt", "r", stdin);
	char a[100010];
    while( cin>>a )
    {
    	bool isgood[300];
    	memset(isgood, false, sizeof(isgood));
    	int lena = strlen(a);
    	for (int i = 0; i < lena ; ++i)
    	{
    		isgood[a[i]] = true;
    	}
    	char _a[100010];
    	cin>>_a;
    	int len_a = strlen(_a);
    	int t;
    	cin>>t;
    	while ( t-- )
    	{
    		char str[100010];
    		cin>>str;
    		int len_str = strlen(str);
    		int RET = 1;
    		for (int i = 0, j = 0; i < len_a && j < len_str; ++i, ++j)
    		{
    			if ( _a[i] == str[j] )
    			{
    				continue;
    			}
    			else{
    				if ( _a[i] == '?' )
    				{
    					if (  isgood[str[j]] == true )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else if ( _a[i] == '*')
    				{
    					int flag = 1;
    					if ( _a[i+1] == str[j] )
    					{
    						flag = 1;
    					}
    					else{
	    					for( ;_a[i]!=str[j] && j < len_str; j++)
	    					{
	    						if ( isgood[str[j]] == false )
	    						{
	    							continue;
	    						}
	    						else{
	    							flag = 0;
	    							break;
	    						}
	    					}
	    				}
    					if ( flag )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else{
    					RET = 0;
    					break;
    				}
    			}
    		}
    		if ( RET )
    		{
    			cout<<"YES"<<'\n';
			}
			else{
				cout<<"NO"<<'\n';
			}
    	}
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main(int argc, char const *argv[])
{
	//freopen("C:\\Users\\tiger\\Desktop\\b.txt", "r", stdin);
	char _a[100010];
    while( cin>>_a )
    {
    	bool isgood[400];
    	memset(isgood, false, sizeof(isgood));
    	int lena = strlen(_a);
    	for (int i = 0; i < lena ; ++i)
    	{
    		isgood[_a[i]] = true;
    	}
    	char a[100010];
    	cin>>a;
    	int len_a = strlen(a);

    	int t;
    	cin>>t;
    	while ( t-- )
    	{
    		char str[100010];
    		memset(str, '\0', sizeof(str));
    		cin>>str;
    		int len_str = strlen(str);
    		int number_star;
			if ( len_str < len_a )
			{
				if ( len_a - len_str > 1 )
				{
					cout<<"NO"<<endl;
					continue;
				}
				else{
					number_star = 1;
				}
			}
			else{
				number_star = len_str - len_a + 1;
			}

    		int RET = 1;
    		for (int i = 0, j = 0; i < len_a && j < len_str; ++i, ++j)
    		{
    			if ( a[i] == str[j] )
    			{
    				continue;
    			}
    			else{
    				if ( a[i] == '?' )
    				{
    					if (  isgood[str[j]] == true )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else if ( a[i] == '*' )
    				{
    					int flag = 1;
    					for(int cnt = 0; cnt < number_star; ++cnt, ++j)
    					{
    						if ( isgood[str[j]] == false )
    						{
    							continue;
    						}
    						else{
    							flag = 0;
    							break;
    						}
    					}
    					--j;
    					if ( flag )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else{
    					RET = 0;
    					break;
    				}
    			}
    		}
    		if ( RET )
    		{
    			cout<<"YES"<<'\n';
			}
			else{
				cout<<"NO"<<'\n';
			}
    	}
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main(int argc, char const *argv[])
{
	//freopen("C:\\Users\\tiger\\Desktop\\b.txt", "r", stdin);
	char _a[100010];
    while( cin>>_a )
    {
    	bool isgood[400];
    	memset(isgood, false, sizeof(isgood));
    	int lena = strlen(_a);
    	for (int i = 0; i < lena ; ++i)
    	{
    		isgood[_a[i]] = true;
    	}
    	char a[100010];
    	cin>>a;
    	int len_a = strlen(a);

    	int t;
    	cin>>t;
    	while ( t-- )
    	{
    		char str[100010];
    		memset(str, '\0', sizeof(str));
    		cin>>str;
    		int len_str = strlen(str);
    		int number_star;
			if ( len_str < len_a )
			{
				if ( len_a - len_str > 1 )
				{
					cout<<"NO"<<endl;
					continue;
				}
				else{
					number_star = 1;
				}
			}
			else{
				number_star = len_str - len_a + 1;
			}

    		int RET = 1;
    		for (int i = 0, j = 0; i < len_a ; ++i, ++j)
    		{
    			if ( a[i] == str[j] )
    			{
    				continue;
    			}
    			else{
    				if ( a[i] == '?' )
    				{
    					if (  isgood[str[j]] == true )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else if ( a[i] == '*' )
    				{
    					int flag = 1;
    					for(int cnt = 0; cnt < number_star; ++cnt, ++j)
    					{
    						if ( isgood[str[j]] == false )
    						{
    							continue;
    						}
    						else{
    							flag = 0;
    							break;
    						}
    					}
    					if ( flag )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else{
    					RET = 0;
    					break;
    				}
    			}
    		}
    		if ( RET )
    		{
    			cout<<"YES"<<'\n';
			}
			else{
				cout<<"NO"<<'\n';
			}
    	}
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main(int argc, char const *argv[])
{
	//freopen("C:\\Users\\tiger\\Desktop\\b.txt", "r", stdin);
	char _a[100010];
    while( cin>>_a )
    {
    	bool isgood[400];
    	memset(isgood, false, sizeof(isgood));
    	int lena = strlen(_a);
    	for (int i = 0; i < lena ; ++i)
    	{
    		isgood[_a[i]] = true;
    	}
    	char a[100010];
    	cin>>a;
    	int len_a = strlen(a);

    	int t;
    	cin>>t;
    	while ( t-- )
    	{
    		char str[100010];
    		memset(str, '\0', sizeof(str));
    		cin>>str;
    		int len_str = strlen(str);
    		int number_star;
			if ( len_str < len_a )
			{
				if ( len_a - len_str > 1 )
				{
					cout<<"NO"<<endl;
					continue;
				}
				else{
					number_star = 0;
				}
			}
			else{
				number_star = len_str - len_a + 1;
			}
    		int cnt = 0;
    		int RET = 1;
    		for (int i = 0, j = 0; i < len_a ; ++i)
    		{
    			if ( a[i] == str[j] )
    			{
    				j++;
    				continue;
    			}
    			else{
    				if ( a[i] == '?' )
    				{
    					if ( isgood[str[j]] == true )
    					{
    						j++;
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else if ( a[i] == '*' )
    				{
    					cnt++;
    					if ( cnt > 1 )
    					{
    						RET = 0;
    						break;
    					}
    					int flag = 1;
    					for(int cnt = 0; cnt < number_star; ++cnt, ++j)
    					{
    						if( j > len_str )
    						{
    							flag = 0;
    							break;
							}
    						if ( isgood[str[j]] == false )
    						{
    							continue;
    						}
    						else{
    							flag = 0;
    							break;
    						}
    					}
    					if ( flag )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else{
    					RET = 0;
    					break;
    				}
    			}
    		}
    		if ( RET )
    		{
    			cout<<"YES"<<'\n';
			}
			else{
				cout<<"NO"<<'\n';
			}
    	}
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main(int argc, char const *argv[])
{
	//freopen("C:\\Users\\tiger\\Desktop\\b.txt", "r", stdin);
	char _a[100010];
    while( cin>>_a )
    {
    	bool isgood[300];
    	memset(isgood, false, sizeof(isgood));
    	int lena = strlen(_a);
    	for (int i = 0; i < lena ; ++i)
    	{
    		isgood[_a[i]] = true;
    	}
    	char a[100010];
    	cin>>a;
    	int len_a = strlen(a);
    	int t;
    	cin>>t;
    	while ( t-- )
    	{
    		char str[100010];
    		cin>>str;
    		int len_str = strlen(str);
    		int RET = 1;
    		for (int i = 0, j = 0; i < len_a && j < len_str; ++i, ++j)
    		{
    			if ( a[i] == str[j] )
    			{
    				continue;
    			}
    			else{
    				if ( a[i] == '?' )
    				{
    					if (  isgood[str[j]] == true )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else if ( a[i] == '*')
    				{
    					i++;
    					int flag = 1;
    					if ( i == len_a )
    					{
    						for ( ; j < len_str; ++j)
    						{
    							if ( isgood[str[j]] == false )
    							{
    								continue;
    							}
    							else{
    								flag = 0;
    								break;
    							}
    						}
    					}
    					else{
	    					for( ;a[i]!=str[j] && j < len_str; j++)
	    					{
	    						if ( isgood[str[j]] == false )
	    						{
	    							continue;
	    						}
	    						else{
	    							flag = 0;
	    							break;
	    						}
	    					}
	    				}
    					if ( flag )
    					{
    						continue;
    					}
    					else{
    						RET = 0;
    						break;
    					}
    				}
    				else{
    					RET = 0;
    					break;
    				}
    			}
    		}
    		if ( RET )
    		{
    			cout<<"YES"<<'\n';
			}
			else{
				cout<<"NO"<<'\n';
			}
    	}
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

string s,ss,good;
int l,ll,n;

bool baik( string s,char ss){
	int lo = s.length();
	for(int j=0;j<lo;j++) if(s[j] == ss) return true;
	return false;
}

bool coba(string s, string ss){
	for(int i=0;i<l-1;i++){
		if(s[i] == '?'){
			if(!baik(good,ss[i])) return false;
		}
		else if(s[i] != ss[i]) return false;
	}
	int asd = ss.length();
	if(asd > l-1) return false;
	return true;
}

int main(){
	cin>>good;
	cin>>s;
	cin>>n;
	l = s.length();
	for(int ii=1;ii<=n;ii++){
		cin>>ss;
		bool cek = true;
		ll = ss.length();
		for(int i=0;i<l;i++){
			if(s[i] == '?'){
				if(!baik(good,ss[i]))
					cek = false;
			}
			else if(s[i] == '*'){
				if(baik(good,ss[i]))
					cek = false;
			}
			else if(s[i] != ss[i]) cek = false;
		}
		if(ll > l) cek = false;
		string cop = s;
		for(int i=0;i<l;i++) if(cop[i] == '*') cop.erase(i,1);
		if(cek || coba(cop,ss)) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

string s,ss,good;
int l,ll,n;

bool baik( string s,char ss){
	int lo = s.length();
	for(int j=0;j<lo;j++) if(s[j] == ss) return true;
	return false;
}

int main(){
	cin>>good;
	cin>>s;
	cin>>n;
	l = s.length();
	for(int ii=1;ii<=n;ii++){
		cin>>ss;
		bool cek = true;
		ll = ss.length();
		int i = 0;
		while(s[i] != '*' && i<l){
			if(s[i] == '?'){
				if(!baik(good,ss[i]))
					cek = false;
			}
			else if(s[i] != ss[i]) cek = false;
			i++;
		}
		for(int j=i; j<i+ll-l;j++)
			if(baik(good,ss[j])) cek = false;
		i++;
		for(int j=i+ll-l;j<ll;j++){
			if(s[i] == '?'){
				if(!baik(good,ss[j]))
					cek = false;
			}
			else if(s[i] != ss[j]) 	cek = false;
			i++;
		}
		if(cek) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
		}
}


#include<bits/stdc++.h>
using namespace std;

string s,ss,good;
int l,ll,n;

bool baik( string s,char ss){
	int lo = s.length();
	for(int j=0;j<lo;j++) if(s[j] == ss) return true;
	return false;
}

bool coba(string s, string ss){
	for(int i=0;i<l-1;i++){
		if(s[i] == '?'){
			if(!baik(good,ss[i])) return false;
		}
		else if(s[i] != ss[i]) return false;
	}
	int asd = ss.length();
	if(asd != (l-1)) return false;
	return true;
}

int main(){
	cin>>good;
	cin>>s;
	cin>>n;
	l = s.length();
	for(int ii=1;ii<=n;ii++){
		cin>>ss;
		bool cek = true;
		ll = ss.length();
		int i = 0;
		if((ll+1)>=l){
			//cout<<"hai"<<endl;
			while(s[i] != '*' && i<l){
				if(s[i] == '?'){
					if(!baik(good,ss[i]))
						cek = false;
				}
				else if(s[i] != ss[i]) cek = false;
				i++;
			}
			//cout<<"hai"<<endl;
			for(int j=i; j<=i+ll-l;j++){
				if(baik(good,ss[j])) cek = false;
			//	cout<<"ads"<<endl;
			}
		//	cout<<i<<endl;
			i++;
			int last = 0;
			for(int j=i+ll-l;j<ll;j++){
				if(s[i] == '?'){
					if(!baik(good,ss[j]))
						cek = false;
				}
				else if(s[i] != ss[j])
					cek = false;
			//	cout<<j<<endl;
				i++;
				last  = j;
			}
			if(cek && last == ss.length()) cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		}
		//string cop = s;
		//for(int i=0;i<l;i++) if(cop[i] == '*') cop.erase(i,1);
		else cout<<"NO"<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

string s,ss,good;
int l,ll,n;

bool baik( string s,char ss){
	int lo = s.length();
	for(int j=0;j<lo;j++) if(s[j] == ss) return true;
	return false;
}

bool coba(string s, string ss){
	for(int i=0;i<l-1;i++){
		if(s[i] == '?'){
			if(!baik(good,ss[i])) return false;
		}
		else if(s[i] != ss[i]) return false;
	}
	int asd = ss.length();
	if(asd != (l-1)) return false;
	return true;
}

int main(){
	cin>>good;
	cin>>s;
	cin>>n;
	l = s.length();
	for(int ii=1;ii<=n;ii++){
		cin>>ss;
		bool cek = true;
		ll = ss.length();
		int i = 0;
		if((ll+1)>=l){
			//cout<<"hai"<<endl;
			while(s[i] != '*' && i<l){
				if(s[i] == '?'){
					if(!baik(good,ss[i]))
						cek = false;
				}
				else if(s[i] != ss[i]) cek = false;
				i++;
			}
			//cout<<"hai"<<endl;
			for(int j=i; j<=i+ll-l;j++){
				if(baik(good,ss[j])) cek = false;
			//	cout<<"ads"<<endl;
			}
		//	cout<<i<<endl;
			i++;
			for(int j=i+ll-l;j<ll;j++){
				if(s[i] == '?'){
					if(!baik(good,ss[j]))
						cek = false;
				}
				else if(s[i] != ss[j])
					cek = false;
			//	cout<<j<<endl;
				i++;
			}
			if(cek) cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		}
		//string cop = s;
		//for(int i=0;i<l;i++) if(cop[i] == '*') cop.erase(i,1);
		else cout<<"NO"<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

string s,ss,good;
int l,ll,n;

bool baik( string s,char ss){
	int lo = s.length();
	for(int j=0;j<lo;j++) if(s[j] == ss) return true;
	return false;
}

int main(){
	cin>>good;
	cin>>s;
	cin>>n;
	l = s.length();
	for(int ii=1;ii<=n;ii++){
		cin>>ss;
		bool cek = true;
		ll = ss.length();
		int i = 0;
		if((ll+1) >= l){
		while(s[i] != '*' && i<l){
			if(s[i] == '?'){
				if(!baik(good,ss[i]))
					cek = false;
			}
			else if(s[i] != ss[i]) cek = false;
			i++;
		}
		for(int j=i; j<i+ll-l;j++)
			if(baik(good,ss[j])) cek = false;
		i++;
		for(int j=i+ll-l;j<ll;j++){
			if(s[i] == '?'){
				if(!baik(good,ss[j]))
					cek = false;
			}
			else if(s[i] != ss[j]) 	cek = false;
			i++;
		}
		if(cek) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
		}
		else cout<<"NO"<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

string s,ss,good;
int l,ll,n;

bool baik( string s,char ss){
	int lo = s.length();
	for(int j=0;j<lo;j++) if(s[j] == ss) return true;
	return false;
}

int main(){
	cin>>good;
	cin>>s;
	cin>>n;
	l = s.length();
	for(int ii=1;ii<=n;ii++){
		cin>>ss;
		bool cek = true;
		ll = ss.length();
		int i = 0;
		if((ll+1) > l){
		while(s[i] != '*' && i<l){
			if(s[i] == '?'){
				if(!baik(good,ss[i]))
					cek = false;
			}
			else if(s[i] != ss[i]) cek = false;
			i++;
		}
		for(int j=i; j<i+ll-l;j++)
			if(baik(good,ss[j])) cek = false;
		i++;
		for(int j=i+ll-l;j<ll;j++){
			if(s[i] == '?'){
				if(!baik(good,ss[j]))
					cek = false;
			}
			else if(s[i] != ss[j]) 	cek = false;
			i++;
		}
		if(cek) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
		}
		else cout<<"NO"<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

string s,ss,good;
int l,ll,n;

bool baik( string s,char ss){
	int lo = s.length();
	for(int j=0;j<lo;j++) if(s[j] == ss) return true;
	return false;
}

bool coba(string s, string ss){
	for(int i=0;i<l-1;i++){
		if(s[i] == '?'){
			if(!baik(good,ss[i])) return false;
		}
		else if(s[i] != ss[i]) return false;
	}
	int asd = ss.length();
	if(asd > l-1) return false;
	return true;
}

int main(){
	cin>>good;
	cin>>s;
	cin>>n;
	l = s.length();
	for(int ii=1;ii<=n;ii++){
		cin>>ss;
		bool cek = true;
		ll = ss.length();
		for(int i=0;i<l;i++){
			if(s[i] == '?'){
				if(!baik(good,ss[i]))
					cek = false;
			}
			else if(s[i] == '*'){
			}
			else if(s[i] != ss[i]) cek = false;
		}
		if(ll > l) cek = false;
		string cop = s;
		for(int i=0;i<l;i++) if(cop[i] == '*') cop.erase(i,1);
		if(cek || coba(cop,ss)) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

string s,ss,good;
int l,ll,n;

bool baik( string s,char ss){
	int lo = s.length();
	for(int j=0;j<lo;j++) if(s[j] == ss) return true;
	return false;
}

int main(){
	cin>>good;
	cin>>s;
	cin>>n;
	l = s.length();
	for(int ii=1;ii<=n;ii++){
		cin>>ss;
		bool cek = true;
		ll = ss.length();
		int i = 0;
		if((ll+1)>=l){
			//cout<<"hai"<<endl;
			while(s[i] != '*' && i<l){
				if(s[i] == '?'){
					if(!baik(good,ss[i]))
						cek = false;
				}
				else if(s[i] != ss[i]) cek = false;
				i++;
			}
			//cout<<"hai"<<endl;
			for(int j=i; j<=i+ll-l;j++){
				if(baik(good,ss[j])) cek = false;
			//	cout<<"ads"<<endl;
			}
		//	cout<<i<<endl;
			i++;
			for(int j=i+ll-l;j<ll;j++){
				if(s[i] == '?'){
					if(!baik(good,ss[j]))
						cek = false;
				}
				else if(s[i] != ss[j])
					cek = false;
			//	cout<<j<<endl;
				i++;
			}
			if(cek) cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		}
		//string cop = s;
		//for(int i=0;i<l;i++) if(cop[i] == '*') cop.erase(i,1);
		else cout<<"NO"<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

string s,ss,good;
int l,ll,n;

bool baik( string s,char ss){
	int lo = s.length();
	for(int j=0;j<lo;j++) if(s[j] == ss) return true;
	return false;
}

int main(){
	cin>>good;
	cin>>s;
	cin>>n;
	l = s.length();
	for(int ii=1;ii<=n;ii++){
		cin>>ss;
		bool cek = true;
		ll = ss.length();
		int i = 0;
			//cout<<"hai"<<endl;
			while(s[i] != '*' && i<l){
				if(s[i] == '?'){
					if(!baik(good,ss[i]))
						cek = false;
				}
				else if(s[i] != ss[i]) cek = false;
				i++;
			}
			bool ketemu = false;
			if(s[i] == '*') ketemu = true;
		//	cout<<i<<endl;
			for(int j=i; j<i+ll-l;j++){
				if(baik(good,ss[j])) cek = false;
			//	cout<<"ads"<<endl;
			}
		//	cout<<i<<endl;
			i++;
			for(int j=i+ll-l;j<ll;j++){
				if(s[i] == '?'){
					if(!baik(good,ss[j]))
						cek = false;
				}
				else if(s[i] != ss[j])
					cek = false;
			//	cout<<j<<endl;
				i++;
			}
			if(!ketemu && ll>l) cout<<"NO"<<endl;
			else if(cek) cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

string s,ss,good;
int l,ll,n;

bool baik( string s,char ss){
	int lo = s.length();
	for(int j=0;j<lo;j++) if(s[j] == ss) return true;
	return false;
}

int main(){
	cin>>good;
	cin>>s;
	cin>>n;
	l = s.length();
	for(int ii=1;ii<=n;ii++){
		cin>>ss;
		bool cek = true;
		ll = ss.length();
		int i = 0;
		if((ll+1)>=l){
			//cout<<"hai"<<endl;
			while(s[i] != '*' && i<l){
				if(s[i] == '?'){
					if(!baik(good,ss[i]))
						cek = false;
				}
				else if(s[i] != ss[i]) cek = false;
				i++;
			}
			bool ketemu = true;
			if(i == l) ketemu = false;
			//cout<<"hai"<<endl;
			for(int j=i; j<=i+ll-l;j++){
				if(baik(good,ss[j])) cek = false;
			//	cout<<"ads"<<endl;
			}
		//	cout<<i<<endl;
			i++;
			for(int j=i+ll-l;j<ll;j++){
				if(s[i] == '?'){
					if(!baik(good,ss[j]))
						cek = false;
				}
				else if(s[i] != ss[j])
					cek = false;
			//	cout<<j<<endl;
				i++;
			}
			if(!ketemu && ll>l) cout<<"NO"<<endl;
			else if(cek) cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		}
		//string cop = s;
		//for(int i=0;i<l;i++) if(cop[i] == '*') cop.erase(i,1);
		else cout<<"NO"<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

string s,ss,good;
int l,ll,n;

bool baik( string s,char ss){
	int lo = s.length();
	for(int j=0;j<lo;j++) if(s[j] == ss) return true;
	return false;
}

bool coba(string s, string ss){
	for(int i=0;i<l-1;i++){
		if(s[i] == '?'){
			if(!baik(good,ss[i])) return false;
		}
		else if(s[i] != ss[i]) return false;
	}
	int asd = ss.length();
	if(asd != (l-1)) return false;
	return true;
}

int main(){
	cin>>good;
	cin>>s;
	cin>>n;
	l = s.length();
	for(int ii=1;ii<=n;ii++){
		cin>>ss;
		bool cek = true;
		ll = ss.length();
		int i = 0;
		if((ll+1)>=l){
			//cout<<"hai"<<endl;
			while(s[i] != '*' && i<l){
				if(s[i] == '?'){
					if(!baik(good,ss[i]))
						cek = false;
				}
				else if(s[i] != ss[i]) cek = false;
				i++;
			}
			//cout<<"hai"<<endl;
			for(int j=i; j<=i+ll-l;j++)
				if(baik(good,ss[j])) cek = false;
		//	cout<<i<<endl;
			i++;
			for(int j=i+1+ll-l;j<ll;j++){
				if(s[i] == '?'){
					if(!baik(good,ss[j]))
						cek = false;
				}
				else if(s[i] != ss[j])
					cek = false;
				i++;
			}
			if(cek) cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		}
		//string cop = s;
		//for(int i=0;i<l;i++) if(cop[i] == '*') cop.erase(i,1);
		else cout<<"NO"<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

string s,ss,good;
int l,ll,n;

bool baik( string s,char ss){
	int lo = s.length();
	for(int j=0;j<lo;j++) if(s[j] == ss) return true;
	return false;
}

int main(){
	cin>>good;
	cin>>s;
	cin>>n;
	l = s.length();
	for(int ii=1;ii<=n;ii++){
		cin>>ss;
		bool cek = true;
		ll = ss.length();
		int i = 0;
		if((ll+1)>=l){
			//cout<<"hai"<<endl;
			while(s[i] != '*' && i<l){
				if(s[i] == '?'){
					if(!baik(good,ss[i]))
						cek = false;
				}
				else if(s[i] != ss[i]) cek = false;
				i++;
			}
			bool ketemu = false;
			if(s[i] == '*') ketemu = true;
		//	cout<<i<<endl;
			for(int j=i; j<i+ll-l;j++){
				if(baik(good,ss[j])) cek = false;
			//	cout<<"ads"<<endl;
			}
		//	cout<<i<<endl;
			i++;
			for(int j=i+ll-l;j<ll;j++){
				if(s[i] == '?'){
					if(!baik(good,ss[j]))
						cek = false;
				}
				else if(s[i] != ss[j])
					cek = false;
			//	cout<<j<<endl;
				i++;
			}
			if(!ketemu && ll>l) cout<<"NO"<<endl;
			else if(cek) cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		}
		//string cop = s;
		//for(int i=0;i<l;i++) if(cop[i] == '*') cop.erase(i,1);
		else cout<<"NO"<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string ptn,s,t,u,v;
map<char,int>mp;
bool check(string s,string t,int l)
{
    int i;
    fr(i,l)
    {
        if(isalpha(s[i])) {
            if(s[i]!=t[i]) return false;
        }
        else if(!mp[t[i]]) return false;
    }
    return true;
}
main()
{
    //read();
    int n,i,j,k;
    while(cin>>s>>ptn)
    {
        int l=ptn.size();
        fr(i,s.size())
        {
             mp[s[i]]=1;
        }
        scanf("%d",&n);
        getchar();
        fr(i,n)
        {
            bool ck=true;
            cin>>t;
            int l1=t.size();
            int pos=ptn.find('*');
            if(pos!=-1) {
                if(l1>=l-1) {
                    if(pos!=0&&pos!=l-1) {
                        u=ptn.substr(0,pos-0);
                        v=t.substr(0,pos-0);
                        if(!check(u,v,u.size())) ck=false;
                        if(ck) {
                            for(j=l-1,k=l1-1;j>pos;j--,k--) {
                                if(isalpha(ptn[j])) {
                                    if(ptn[j]!=t[k]) {
                                        ck=false;
                                        break;
                                    }
                                }
                                else if(!mp[t[k]]) {
                                        ck=false;
                                        break;
                                }
                            }
                        }
                        if(ck) {
                            for(j=pos;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck) printf("YES\n");
                        else   printf("NO\n");
                    }
                    else if(pos==l-1) {
                        string u=ptn.substr(0,l-1);
                        string v=t.substr(0,l-1);
                        if(!check(u,v,l-1)) ck=false;
                        if(ck) {
                            for(j=pos;j<l1;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                    else {
                        for(j=l-1,k=l1-1;j>0;j--,k--) {
                            if(isalpha(ptn[j])) {
                                if(ptn[j]!=t[k]) {
                                    ck=false;
                                    break;
                                }
                            }
                            else if(!mp[t[k]]) {
                                    ck=false;
                                    break;
                            }
                        }
                        if(ck) {
                            for(j=pos;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                }
                else printf("NO\n");
            }
            else {
                if(ptn.size()!=t.size()) printf("NO\n");
                else {
                    if(check(ptn,t,t.size())) printf("YES\n");
                    else printf("NO\n");
                }
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string ptn,s,t,u,v;
map<char,int>mp;
bool check(string s,string t,int l)
{
    int i;
    fr(i,l)
    {
        if(isalpha(s[i])) {
            if(s[i]!=t[i]) return false;
        }
        else if(!mp[t[i]]) return false;
    }
    return true;
}
main()
{
    //read();
    int n,i,j,k;
    while(cin>>s>>ptn)
    {
        int l=ptn.size();
        fr(i,s.size())
        {
             mp[s[i]]++;
        }
        scanf("%d",&n);
        getchar();
        fr(i,n)
        {
            bool ck=true;
            cin>>t;
            int l1=t.size();
            int pos=ptn.find('*');
            if(pos!=-1) {
                if(l1>=l-1) {
                    if(pos!=0&&pos!=l-1) {
                        u=ptn.substr(0,pos-0);
                        v=t.substr(0,pos-0);
                        if(!check(u,v,u.size())) ck=false;
                        if(ck) {
                            for(j=l-1,k=l1-1;j>pos;j--,k--) {
                                if(isalpha(ptn[j])) {
                                    if(ptn[j]!=t[k]) {
                                        ck=false;
                                        break;
                                    }
                                }
                                else if(!mp[t[k]]) {
                                        ck=false;
                                        break;
                                }
                            }
                        }
                        if(ck) {
                            for(j=pos;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck) printf("YES\n");
                        else   printf("NO\n");
                    }
                    else if(pos==l-1) {
                        string u=ptn.substr(0,l-1);
                        string v=t.substr(0,l-1);
                        if(!check(u,v,l-1)) ck=false;
                        if(ck) {
                            for(j=pos;j<l1;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                    else {
                        for(j=l-1,k=l1-1;j>0;j--,k--) {
                            if(isalpha(ptn[j])) {
                                if(ptn[j]!=t[k]) {
                                    ck=false;
                                    break;
                                }
                            }
                            else if(!mp[t[k]]) {
                                    ck=false;
                                    break;
                            }
                        }
                        if(ck) {
                            for(j=pos;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                }
                else printf("NO\n");
            }
            else {
                if(ptn.size()!=t.size()) printf("NO\n");
                else {
                    if(check(ptn,t,t.size())) printf("YES\n");
                    else printf("NO\n");
                }
            }
        }
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string ptn,s,t;
map<char,int>mp;
main()
{
    //read();
    int n,i,j,k;
    while(cin>>s>>ptn)
    {
        int l=ptn.size();
        fr(i,s.size())
        {
             mp[s[i]]=1;
        }
        scanf("%d",&n);
        getchar();
        fr(i,n)
        {
            int cnt=0,sz=0;
            bool ck=true;
            cin>>t;
            int l1=t.size();
            if(l1<l-1) printf("NO\n");
            else {
                fr(j,l1)
                {
                    if(ptn[j]=='*') {
                        sz=l1-l;
                        for(k=j;k<=j+sz;k++) {
                            if(mp[t[k]]) {
                                ck=false;
                                break;
                            }
                            cnt++;
                        }
                        if(cnt>0) cnt--;
                        j+=cnt;
                    }
                    else if(isalpha(ptn[j])&&ptn[j]!=t[j-sz]) ck=false;
                    else if(!mp[t[j-sz]]) ck=false;
                    if(!ck) break;
                }
                if(ck)  printf("YES\n");
                else    printf("NO\n");
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string ptn,s,t;
map<char,int>mp;
main()
{
    //read();
    int n,i,j,k;
    while(cin>>s>>ptn)
    {
        int l=ptn.size();
        fr(i,s.size())
        {
             mp[s[i]]=1;
        }
        scanf("%d",&n);
        getchar();
        fr(i,n)
        {
            int cnt=0,sz=0;
            bool ck=true;
            cin>>t;
            int l1=t.size();
            if(l1>=l-1) {
                fr(j,l1)
                {
                    if(ptn[j]=='*') {
                        sz=l1-l;
                        for(k=j;k<=j+sz;k++) {
                            if(mp[t[k]]) {
                                ck=false;
                                break;
                            }
                            cnt++;
                        }
                        if(cnt>0) cnt--;
                    }
                    else if(isalpha(ptn[j])&&ptn[j]!=t[cnt]) ck=false;
                    else if(!mp[t[cnt]]) ck=false;
                    cnt++;
                    if(!ck) break;
                }
                if(ck)  printf("YES\n");
                else    printf("NO\n");
            }
            else        printf("NO\n");
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string ptn,s,t,u,v;
map<char,int>mp;
bool check(string s,string t,int l)
{
    int i;
    fr(i,l)
    {
        if(isalpha(s[i])) {
            if(s[i]!=t[i]) return false;
        }
        else if(!mp[t[i]]) return false;
    }
    return true;
}
main()
{
    read();
    int n,i,j,k;
    while(cin>>s>>ptn)
    {
        int l=ptn.size();
        fr(i,s.size())
        {
             mp[s[i]]++;
        }
        scanf("%d",&n);
        getchar();
        fr(i,n)
        {
            bool ck=true;
            cin>>t;
            int l1=t.size();
            int pos=ptn.find('*');
            if(pos!=-1) {
                if(l1>=l-1) {
                    if(pos!=0&&pos!=l-1) {
                        u=ptn.substr(0,pos-0);
                        v=t.substr(0,pos-0);
                        if(!check(u,v,u.size())) ck=false;
                        if(ck) {
                            for(j=l-1,k=l1-1;j>pos;j--,k--) {
                                if(isalpha(ptn[j])) {
                                    if(ptn[j]!=t[j]) {
                                        ck=false;
                                        break;
                                    }
                                }
                                else if(!mp[t[j]]) {
                                        ck=false;
                                        break;
                                }
                            }
                        }
                        if(ck) {
                            for(j=pos;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck) printf("YES\n");
                        else   printf("NO\n");
                    }
                    else if(pos==l-1) {
                        string u=ptn.substr(0,l-1);
                        string v=t.substr(0,l-1);
                        if(!check(u,v,l-1)) ck=false;
                        if(ck) {
                            for(j=pos;j<l1;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                    else {
                        for(j=l-1,k=l1-1;j>0;j--,k--) {
                            if(isalpha(ptn[j])) {
                                if(ptn[j]!=t[j]) {
                                    ck=false;
                                    break;
                                }
                            }
                            else if(!mp[t[j]]) {
                                    ck=false;
                                    break;
                            }
                        }
                        if(ck) {
                            for(j=pos;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                }
                else printf("NO\n");
            }
            else {
                if(ptn.size()!=t.size()) printf("NO\n");
                else {
                    if(check(ptn,t,t.size())) printf("YES\n");
                    else printf("NO\n");
                }
            }
        }
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string s,q,pat;
map<char,int>mp;
main()
{
    int n,i,j,k;
    while(cin>>s>>pat)
    {
        fr(i,s.size()) mp[s[i]]++;
        int l=pat.size();
        cin>>n;
        getchar();
        fr(k,n)
        {
            cin>>q;
            int l1=q.size();
            bool ch=true;
            int cnt=0,sz=0,cur=0,ind=-1;
            if(l1>=l-1) {
                fr(i,l)
                {
                    if(pat[i]=='*') {
                        ind=i+1;
                        sz=l1-(l-1);
                        for(j=i;j<=i+sz;j++) {
                            if(mp[q[j]]) ch=false;
                        }
                        cur+=sz-1;
                    }
                    else if(isalpha(pat[i])) {
                        if(pat[i]==q[cur]) cnt++;
                        else {
                            cur++;
                            continue;
                        }
                    }
                    else if(mp[q[cur]]) cnt++;
                    cur++;
                }
                //cout<<cnt<<endl;
                if(ind>0) {
                    if((cnt==l1-sz)&&(ch)) printf("YES\n");
                    else printf("NO\n");
                }
                else if(cnt==l1) printf("YES\n");
                else printf("NO\n");
            }
            else printf("NO\n");
        }
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string ptn,s,t;
map<char,int>mp;
main()
{
    //read();
    int n,i,j,k;
    while(cin>>s>>ptn)
    {
        int l=ptn.size();
        fr(i,s.size())
        {
             mp[s[i]]=1;
        }
        scanf("%d",&n);
        getchar();
        fr(i,n)
        {
            int cnt=0,sz=0;
            bool ck=true;
            cin>>t;
            int l1=t.size();
            if(l1>=l-1) {
                fr(j,l1)
                {
                    if(ptn[j]=='*') {
                        sz=l1-l;
                        for(k=j;k<=j+sz;k++) {
                            if(mp[t[k]]) {
                                ck=false;
                                break;
                            }
                            cnt++;
                        }
                        if(cnt>0) cnt--;
                        j+=cnt;
                    }
                    else if(isalpha(ptn[j])&&ptn[j]!=t[j-sz]) ck=false;
                    else if(!mp[t[j-sz]]) ck=false;
                    if(!ck) break;
                }
                if(ck)  printf("YES\n");
                else    printf("NO\n");
            }
            else        printf("NO\n");
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string ptn,s,t,u,v;
map<char,int>mp;
bool check(string s,string t,int l)
{
    int i;
    fr(i,l)
    {
        if(isalpha(s[i])) {
            if(s[i]!=t[i]) return false;
        }
        else if(!mp[t[i]]) return false;
    }
    return true;
}
main()
{
    //read();
    int n,i,j,k;
    while(cin>>s>>ptn)
    {
        int l=ptn.size();
        fr(i,s.size())
        {
             mp[s[i]]=1;
        }
        scanf("%d",&n);
        getchar();
        fr(i,n)
        {
            bool ck=true;
            cin>>t;
            int l1=t.size();
            int pos=ptn.find('*');
            if(pos!=-1) {
                if(l1>=l-1) {
                    if(pos!=0&&pos!=l-1) {
                        u=ptn.substr(0,pos-0);
                        v=t.substr(0,pos-0);
                        if(!check(u,v,u.size())) ck=false;
                        if(ck) {
                            for(j=l-1,k=l1-1;j>pos;j--,k--) {
                                if(isalpha(ptn[j])) {
                                    if(ptn[j]!=t[j]) {
                                        ck=false;
                                        break;
                                    }
                                }
                                else if(!mp[t[j]]) {
                                        ck=false;
                                        break;
                                }
                            }
                        }
                        if(ck) {
                            for(j=pos;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck) printf("YES\n");
                        else   printf("NO\n");
                    }
                    else if(pos==l-1) {
                        string u=ptn.substr(0,l-1);
                        string v=t.substr(0,l-1);
                        if(!check(u,v,l-1)) ck=false;
                        if(ck) {
                            for(j=pos;j<l1;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                    else {
                        for(j=l-1,k=l1-1;j>0;j--,k--) {
                            if(isalpha(ptn[j])) {
                                if(ptn[j]!=t[j]) {
                                    ck=false;
                                    break;
                                }
                            }
                            else if(!mp[t[j]]) {
                                    ck=false;
                                    break;
                            }
                        }
                        if(ck) {
                            for(j=pos;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                }
                else printf("NO\n");
            }
            else {
                if(ptn.size()!=t.size()) printf("NO\n");
                else {
                    if(check(ptn,t,t.size())) printf("YES\n");
                    else printf("NO\n");
                }
            }
        }
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string s,q,pat;
map<char,int>mp;
main()
{
    int n,i,j,k;
    while(cin>>s>>pat)
    {
        fr(i,s.size()) mp[s[i]]++;
        int l=pat.size();
        cin>>n;
        getchar();
        fr(k,n)
        {
            cin>>q;
            int l1=q.size();
            bool ch=true;
            int cnt=0,sz=0,cur=0,ind=-1;
            if(l1>=l-1) {
                fr(i,l)
                {
                    if(pat[i]=='*') {
                        ind=i+1;
                        sz=l1-(l-1);
                        for(j=i;j<i+sz;j++) {
                            if(mp[q[j]]) ch=false;
                        }
                        cur+=sz-1;
                    }
                    else if(isalpha(pat[i])) {
                        if(pat[i]==q[cur]) cnt++;
                        else {
                            cur++;
                            continue;
                        }
                    }
                    else if(mp[q[cur]]) cnt++;
                    cur++;
                }
                //cout<<cnt<<endl;
                if(ind>0) {
                    if((cnt==l1-sz)&&(ch)) printf("YES\n");
                    else printf("NO\n");
                }
                else if(cnt==l1&&cnt==l) printf("YES\n");
                else printf("NO\n");
            }
            else printf("NO\n");
        }
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string ptn,s,t;
map<char,int>mp;
bool check(string s,string t,int l)
{
    int i;
    fr(i,l)
    {
        if(isalpha(s[i])) {
            if(s[i]!=t[i]) return false;
        }
        else if(!mp[t[i]]) return false;
    }
    return true;
}
main()
{
    //read();
    int n,i,j,k;
    while(cin>>s>>ptn)
    {
        int l=ptn.size();
        fr(i,s.size())
        {
             mp[s[i]]=1;
        }
        scanf("%d",&n);
        getchar();
        fr(i,n)
        {
            bool ck=true;
            cin>>t;
            int l1=t.size();
            int pos=ptn.find('*');
            if(pos!=-1) {
                if(l1>=l-1) {
                    if(pos!=0&&pos!=l-1) {
                        string u=ptn.substr(0,pos-0);
                        string v=t.substr(0,pos-0);
                        if(!check(u,v,l)) ck=false;
                        if(ck) {
                            for(j=l-1,k=l1-1;j>pos;j--,k--) {
                                if(isalpha(ptn[j])) {
                                    if(ptn[j]!=t[j]) {
                                        ck=false;
                                        break;
                                    }
                                }
                                else if(!mp[t[j]]) {
                                        ck=false;
                                        break;
                                }
                            }
                        }
                        if(ck) {
                            for(j=pos+1;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck) printf("YES\n");
                        else   printf("NO\n");
                    }
                    else if(pos==l-1) {
                        string u=ptn.substr(0,l-1);
                        string v=t.substr(0,l-1);
                        if(!check(u,v,l-1)) ck=false;
                        if(ck) {
                            for(j=pos;j<l1;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                    else {
                        for(j=l-1,k=l1-1;j>0;j--,k--) {
                            if(isalpha(s[i])) {
                                if(s[i]!=t[i]) ck=false;
                                }
                            else if(!mp[t[i]]) ck=false;
                        }
                        if(ck) {
                            for(j=pos;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                }
                else printf("NO\n");
            }
            else {
                if(ptn.size()!=t.size()) printf("NO\n");
                else {
                    if(check(ptn,t,t.size())) printf("YES\n");
                    else printf("NO\n");
                }
            }
        }
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string ptn,s,t,u,v;
map<char,int>mp;
bool check(string s,string t,int l)
{
    int i;
    fr(i,l)
    {
        if(isalpha(s[i])) {
            if(s[i]!=t[i]) return false;
        }
        else if(!mp[t[i]]) return false;
    }
    return true;
}
main()
{
    //read();
    int n,i,j,k;
    while(cin>>s>>ptn)
    {
        int l=ptn.size();
        fr(i,s.size())
        {
             mp[s[i]]++;
        }
        scanf("%d",&n);
        getchar();
        fr(i,n)
        {
            bool ck=true;
            cin>>t;
            int l1=t.size();
            int pos=ptn.find('*');
            if(pos!=-1) {
                if(l1>=l-1) {
                    if(pos!=0&&pos!=l-1) {
                        u=ptn.substr(0,pos-0);
                        v=t.substr(0,pos-0);
                        if(!check(u,v,u.size())) ck=false;
                        if(ck) {
                            for(j=l-1,k=l1-1;j>pos;j--,k--) {
                                if(isalpha(ptn[j])) {
                                    if(ptn[j]!=t[k]) {
                                        ck=false;
                                        break;
                                    }
                                }
                                else if(!mp[t[k]]) {
                                        ck=false;
                                        break;
                                }
                            }
                        }
                        if(ck) {
                            for(j=pos;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck) printf("YES\n");
                        else   printf("NO\n");
                    }
                    else if(pos==l-1) {
                        string u=ptn.substr(0,l-1);
                        string v=t.substr(0,l-1);
                        if(!check(u,v,l-1)) ck=false;
                        if(ck) {
                            for(j=pos;j<l1;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                    else {
                        for(j=l-1,k=l1-1;j>0;j--,k--) {
                            if(isalpha(ptn[j])) {
                                if(ptn[j]!=t[k]) {
                                    ck=false;
                                    break;
                                }
                            }
                            else if(!mp[t[j]]) {
                                    ck=false;
                                    break;
                            }
                        }
                        if(ck) {
                            for(j=pos;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                }
                else printf("NO\n");
            }
            else {
                if(ptn.size()!=t.size()) printf("NO\n");
                else {
                    if(check(ptn,t,t.size())) printf("YES\n");
                    else printf("NO\n");
                }
            }
        }
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string s,q,pat;
map<char,int>mp;
main()
{
    int n,i,j,k;
    while(cin>>s>>pat)
    {
        fr(i,s.size()) mp[s[i]]++;
        int l=pat.size();
        cin>>n;
        getchar();
        fr(k,n)
        {
            cin>>q;
            int l1=q.size();
            bool ch=true;
            int cnt=0,sz=0,cur=0,ind=-1;
            if(l1>=l-1) {
                fr(i,l)
                {
                    if(pat[i]=='*') {
                        ind=i+1;
                        sz=l1-(l-1);
                        for(j=i;j<=i+sz;j++) {
                            if(mp[q[j]]) ch=false;
                        }
                        cur+=sz-1;
                    }
                    else if(isalpha(pat[i])) {
                        if(pat[i]==q[cur]) cnt++;
                        else {
                            cur++;
                            continue;
                        }
                    }
                    else if(mp[q[cur]]) cnt++;
                    cur++;
                }
                //cout<<cnt<<endl;
                if(ind>0) {
                    if(!ch) printf("NO\n");
                    else if(cnt==l1-sz) printf("YES\n");
                    else printf("NO\n");
                }
                else if(cnt==l1) printf("YES\n");
                else printf("NO\n");
            }
            else printf("NO\n");
        }
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string ptn,s,t,u,v;
map<char,int>mp;
bool check(string s,string t,int l)
{
    int i;
    fr(i,l)
    {
        if(isalpha(s[i])) {
            if(s[i]!=t[i]) return false;
        }
        else if(!mp[t[i]]) return false;
    }
    return true;
}
main()
{
    //read();
    int n,i,j,k;
    while(cin>>s>>ptn)
    {
        int l=ptn.size();
        fr(i,s.size())
        {
             mp[s[i]]=1;
        }
        scanf("%d",&n);
        getchar();
        fr(i,n)
        {
            bool ck=true;
            cin>>t;
            int l1=t.size();
            int pos=ptn.find('*');
            if(pos!=-1) {
                if(l1>=l-1) {
                    if(pos!=0&&pos!=l-1) {
                        u=ptn.substr(0,pos-0);
                        v=t.substr(0,pos-0);
                        if(!check(u,v,u.size())) ck=false;
                        if(ck) {
                            for(j=l-1,k=l1-1;j>pos;j--,k--) {
                                if(isalpha(ptn[j])) {
                                    if(ptn[j]!=t[j]) {
                                        ck=false;
                                        break;
                                    }
                                }
                                else if(!mp[t[j]]) {
                                        ck=false;
                                        break;
                                }
                            }
                        }
                        if(ck) {
                            for(j=pos;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck) printf("YES\n");
                        else   printf("NO\n");
                    }
                    else if(pos==l-1) {
                        string u=ptn.substr(0,l-1);
                        string v=t.substr(0,l-1);
                        if(!check(u,v,l-1)) ck=false;
                        if(ck) {
                            for(j=pos;j<l1;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                    else {
                        for(j=l-1,k=l1-1;j>0;j--,k--) {
                            if(isalpha(ptn[j])) {
                                if(ptn[j]!=t[j]) ck=false;
                            }
                            else if(!mp[t[j]]) ck=false;
                        }
                        if(ck) {
                            for(j=pos;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                }
                else printf("NO\n");
            }
            else {
                if(ptn.size()!=t.size()) printf("NO\n");
                else {
                    if(check(ptn,t,t.size())) printf("YES\n");
                    else printf("NO\n");
                }
            }
        }
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string s,q,pat;
map<char,int>mp;
main()
{
    int n,i,j,k;
    while(cin>>s>>pat)
    {
        fr(i,s.size()) mp[s[i]]++;
        int l=pat.size();
        cin>>n;
        getchar();
        fr(k,n)
        {
            cin>>q;
            int l1=q.size();
            bool ch=true;
            int cnt=0,sz=0,cur=0,ind=-1;
            if(l1>=l-1) {
                fr(i,l)
                {
                    if(pat[i]=='*') {
                        ind=i+1;
                        sz=l1-(l-1);
                        for(j=i;j<i+sz;j++) {
                            if(mp[q[j]]) ch=false;
                        }
                        cur+=sz-1;
                    }
                    else if(isalpha(pat[i])) {
                        if(pat[i]==q[cur]) cnt++;
                        else {
                            cur++;
                            continue;
                        }
                    }
                    else if(mp[q[cur]]) cnt++;
                    cur++;
                }
                //cout<<cnt<<endl;
                if(ind>0) {
                    if((cnt==l1-sz)&&(ch)) printf("YES\n");
                    else printf("NO\n");
                }
                else if(cnt==l1) printf("YES\n");
                else printf("NO\n");
            }
            else printf("NO\n");
        }
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string ptn,s,t,u,v;
map<char,int>mp;
bool check(string s,string t,int l)
{
    int i;
    fr(i,l)
    {
        if(isalpha(s[i])) {
            if(s[i]!=t[i]) return false;
        }
        else if(!mp[t[i]]) return false;
    }
    return true;
}
main()
{
    //read();
    int n,i,j,k;
    while(cin>>s>>ptn)
    {
        int l=ptn.size();
        fr(i,s.size())
        {
             mp[s[i]]=1;
        }
        scanf("%d",&n);
        getchar();
        fr(i,n)
        {
            bool ck=true;
            cin>>t;
            int l1=t.size();
            int pos=ptn.find('*');
            if(pos!=-1) {
                if(l1>=l-1) {
                    if(pos!=0&&pos!=l-1) {
                        u=ptn.substr(0,pos-0);
                        v=t.substr(0,pos-0);
                        if(!check(u,v,u.size())) ck=false;
                        if(ck) {
                            for(j=l-1,k=l1-1;j>pos;j--,k--) {
                                if(isalpha(ptn[j])) {
                                    if(ptn[j]!=t[j]) {
                                        ck=false;
                                        break;
                                    }
                                }
                                else if(!mp[t[j]]) {
                                        ck=false;
                                        break;
                                }
                            }
                        }
                        if(ck) {
                            for(j=pos+1;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck) printf("YES\n");
                        else   printf("NO\n");
                    }
                    else if(pos==l-1) {
                        string u=ptn.substr(0,l-1);
                        string v=t.substr(0,l-1);
                        if(!check(u,v,l-1)) ck=false;
                        if(ck) {
                            for(j=pos;j<l1;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                    else {
                        for(j=l-1,k=l1-1;j>0;j--,k--) {
                            if(isalpha(s[i])) {
                                if(s[i]!=t[i]) ck=false;
                                }
                            else if(!mp[t[i]]) ck=false;
                        }
                        if(ck) {
                            for(j=pos;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                }
                else printf("NO\n");
            }
            else {
                if(ptn.size()!=t.size()) printf("NO\n");
                else {
                    if(check(ptn,t,t.size())) printf("YES\n");
                    else printf("NO\n");
                }
            }
        }
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string ptn,s,t;
map<char,int>mp;
main()
{
    //read();
    int n,i,j,k;
    while(cin>>s>>ptn)
    {
        int l=ptn.size();
        fr(i,s.size())
        {
             mp[s[i]]=1;
        }
        scanf("%d",&n);
        getchar();
        fr(i,n)
        {
            int cnt=0,sz=0;
            bool ck=true;
            cin>>t;
            int l1=t.size();
            if(l1<l-1) printf("NO\n");
            else {
                fr(j,l1)
                {
                    if(ptn[j]=='*') {
                        sz=l1-(l-1);
                        for(k=j;k<=j+sz;k++) {
                            if(mp[t[k]]) {
                                ck=false;
                                break;
                            }
                            cnt++;
                        }
                        if(cnt>0) cnt--;
                        j+=cnt;
                    }
                    else if(isalpha(ptn[j])&&ptn[j]!=t[j-sz]) ck=false;
                    else if(!mp[t[j-sz]]) ck=false;
                    if(!ck) break;
                }
                if(ck)  printf("YES\n");
                else    printf("NO\n");
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define  fr(i,a)  for(i=0;i<a;i++)
#define  tc(i,t)  for(i=1;i<=t;i++)
#define  cln(x)   memset(x,0,sizeof(x))
#define  clr(x)   memset(x,-1,sizeof(x))
#define  read()   freopen("input.txt","r",stdin)
#define  write()  freopen("output.txt","w",stdout)
string ptn,s,t,u,v;
map<char,int>mp;
bool check(string s,string t,int l)
{
    int i;
    fr(i,l)
    {
        if(isalpha(s[i])) {
            if(s[i]!=t[i]) return false;
        }
        else if(!mp[t[i]]) return false;
    }
    return true;
}
main()
{
    //read();
    int n,i,j,k;
    while(cin>>s>>ptn)
    {
        int l=ptn.size();
        fr(i,s.size())
        {
             mp[s[i]]++;
        }
        scanf("%d",&n);
        getchar();
        fr(i,n)
        {
            bool ck=true;
            cin>>t;
            int l1=t.size();
            int pos=ptn.find('*');
            if(pos!=-1) {
                if(l1>=l-1) {
                    if(pos!=0&&pos!=l-1) {
                        u=ptn.substr(0,pos-0);
                        v=t.substr(0,pos-0);
                        if(!check(u,v,u.size())) ck=false;
                        if(ck) {
                            for(j=l-1,k=l1-1;j>pos;j--,k--) {
                                if(isalpha(ptn[j])) {
                                    if(ptn[j]!=t[j]) {
                                        ck=false;
                                        break;
                                    }
                                }
                                else if(!mp[t[j]]) {
                                        ck=false;
                                        break;
                                }
                            }
                        }
                        if(ck) {
                            for(j=pos;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck) printf("YES\n");
                        else   printf("NO\n");
                    }
                    else if(pos==l-1) {
                        string u=ptn.substr(0,l-1);
                        string v=t.substr(0,l-1);
                        if(!check(u,v,l-1)) ck=false;
                        if(ck) {
                            for(j=pos;j<l1;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                    else {
                        for(j=l-1,k=l1-1;j>0;j--,k--) {
                            if(isalpha(ptn[j])) {
                                if(ptn[j]!=t[j]) {
                                    ck=false;
                                    break;
                                }
                            }
                            else if(!mp[t[j]]) {
                                    ck=false;
                                    break;
                            }
                        }
                        if(ck) {
                            for(j=pos;j<=k;j++) {
                                if(mp[t[j]]) {
                                    ck=false;
                                    break;
                                }
                            }
                        }
                        if(ck)  printf("YES\n");
                        else    printf("NO\n");
                    }
                }
                else printf("NO\n");
            }
            else {
                if(ptn.size()!=t.size()) printf("NO\n");
                else {
                    if(check(ptn,t,t.size())) printf("YES\n");
                    else printf("NO\n");
                }
            }
        }
        mp.clear();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

string patt , org ;
int f[26] ;

int main()
{
	//scanf("%s%s" , &patt , &org) ;
	cin>>patt>>org ;
	for(int i =0 ; i<patt.size() ; i++)
	{
		//cout<<"AF";
		f[patt[i] - 'a'] = 1 ;
		//printf("%fas");
	}

	int t ;
	scanf("%d" , &t) ;

	while(t--)
	{
		string s ;
	//	scanf("%s" , &s) ;
		cin>>s ;

		int j = org.size()-1 ,  i  , f1 =0 ;

		for( i=0 ; i<s.size() ; i++)
	    {
	    	if(i == org.size())
	    	break ;

	    	if(s[i] == org[i] || (org[i] == '?' && f[s[i]-'a']))
	    	continue ;

	    	if(org[i] == '*')
	    	break ;

	    	f1 =1 ;
		}

		if(i<s.size() &&  i == org.size())
		f1 = 1 ;
	//	if(i == s.size() && i < org.size()  )
	//	f1 = 1;

		int  k = s.size() - 1;

		for(; j>i && k>=i ; j-- , k--)
		{
			if(s[k] == org[j] || (org[j] == '?' && f[s[k] - 'a']))
			continue ;
			f1 = 1 ;

		}

		if(i <= j)
		f1 = 1 ;

		for(; i<=k ;i++)
		{
			if(f[s[i] - 'a'])
			f1 = 1 ;
		}

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


#include<bits/stdc++.h>
using namespace std;

string patt , orig ;
int f[26] ;

int main()
{
	cin>>patt>>orig ;

	for(int i = 0 ; i<patt.size() ; i++)
	{
		f[patt[i] - 'a']= 1;
	}

	int ind , is =0 ;

	for(int i = 0 ; i<orig.size() ; i++)
	{
		if(orig[i] == '*')
		{
			is= 1;
			ind = i ;
		}
	}

	int  t ;
	scanf("%d" , &t) ;

	while(t--)
	{
		string s ;
		cin>>s ;

		int f1=0 ;

		if(!is && s.size() != orig.size())
		f1= 1 ;

		if(is && s.size() < orig.size()-1)
		f1 =1 ;

		if(f1)
		{
			printf("NO\n") ;
			continue ;
		}

		if(!is)
		{
			for(int i  = 0 ; i<orig.size();i++)
			{
				if(s[i] == orig[i] || (orig[i] == '?' && f[s[i] - 'a']))
				continue ;
				f1= 1 ;
			}
		}
		else
		{
			int  i ;
			for( i = 0  ; i<ind ; i++)
		    {
		    	if(s[i] == orig[i] || (orig[i] == '?' && f[s[i] - 'a']))
				continue ;
				f1 = 1 ;
			}
			int  j , k =s.size() -1  ;
			for( j = orig.size() -1 ; j>ind ; j-- , k--)
			{
				if(s[j] == orig[j] || (orig[j] == '?' && f[s[j] - 'a']))
				continue ;
				f1 = 1 ;
			}

			for(; i<=k ; i++)
			{
				if(f[s[i] - 'a'])
				f1= 1 ;
			}
		}

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

}


#include<bits/stdc++.h>
using namespace std;

string patt , org ;
int f[26] ;

int main()
{
	//scanf("%s%s" , &patt , &org) ;
	cin>>patt>>org ;
	for(int i =0 ; i<patt.size() ; i++)
	{
		//cout<<"AF";
		f[patt[i] - 'a'] = 1 ;
		//printf("%fas");
	}

	int t ;
	scanf("%d" , &t) ;

	while(t--)
	{
		string s ;
	//	scanf("%s" , &s) ;
		cin>>s ;

		int j = org.size()-1 ,  i  , f1 =0 ;

		for( i=0 ; i<s.size() ; i++)
	    {
	    	if(i == org.size())
	    	break ;

	    	if(s[i] == org[i] || (org[i] == '?' && f[s[i]-'a']))
	    	continue ;

	    	if(org[i] == '*')
	    	break ;

	    	f1 =1 ;
		}

		if(i<s.size() &&  i == org.size())
		f1 = 1 ;
	//	if(i == s.size() && i < org.size()  )
	//	f1 = 1;

		int  k = s.size() - 1;

		for(; j>i && k>=i ; j-- , k--)
		{
			if(s[k] == org[j] || (org[j] == '?' && f[s[k] - 'a']))
			continue ;
			f1 = 1 ;

		}

		if(i < j)
		f1 = 1 ;

		for(; i<=k ;i++)
		{
			if(f[s[i] - 'a'])
			f1 = 1 ;
		}

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


#include<bits/stdc++.h>
using namespace std;

string patt , org ;
int f[26] ;

int main()
{
	//scanf("%s%s" , &patt , &org) ;
	cin>>patt>>org ;
	for(int i =0 ; i<patt.size() ; i++)
	{
		//cout<<"AF";
		f[patt[i] - 'a'] = 1 ;
		//printf("%fas");
	}

	int t ;
	scanf("%d" , &t) ;

	while(t--)
	{
		string s ;
	//	scanf("%s" , &s) ;
		cin>>s ;

		int j = org.size()-1 ,  i  , f1 =0 ;

		for( i=0 ; i<s.size() ; i++)
	    {
	    	if(i == org.size())
	    	break ;

	    	if(s[i] == org[i] || (org[i] == '?' && f[s[i]-'a']))
	    	continue ;

	    	if(org[i] == '*')
	    	break ;

	    	f1 =1 ;
		}

		if(i<s.size()-1 &&  i == org.size())
		f1 = 1 ;
		if(i == s.size() && i < org.size() -1 )
		f1 = 1;

		int  k = s.size() - 1;

		for(; j>i && k>=i ; j-- , k--)
		{
			if(s[k] == org[j] || (org[j] == '?' && f[s[k] - 'a']))
			continue ;
			f1 = 1 ;

		}

		for(; i<=k ;i++)
		{
			if(f[s[i] - 'a'])
			f1 = 1 ;
		}

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


#include<bits/stdc++.h>
using namespace std;

string patt , orig ;
int f[26] ;

int main()
{
	cin>>patt>>orig ;

	for(int i = 0 ; i<patt.size() ; i++)
	{
		f[patt[i] - 'a']= 1;
	}

	int ind , is =0 ;

	for(int i = 0 ; i<orig.size() ; i++)
	{
		if(orig[i] == '*')
		{
			is= 1;
			ind = i ;
		}
	}

	int  t ;
	scanf("%d" , &t) ;

	while(t--)
	{
		string s ;
		cin>>s ;

		int f1=0 ;

		if(!is && s.size() != orig.size())
		f1= 1 ;

		if(is && s.size() < orig.size()-1)
		f1 =1 ;

		if(f1)
		{
			printf("NO\n") ;
			continue ;
		}

		if(!is)
		{
			for(int i  = 0 ; i<orig.size();i++)
			{
				if(s[i] == orig[i] || (orig[i] == '?' && f[s[i] - 'a']))
				continue ;
				f1= 1 ;
			}
		}
		else
		{
			int  i ;
			//cout<<f1;
			for( i = 0  ; i<ind ; i++)
		    {
		    	if(s[i] == orig[i] || (orig[i] == '?' && f[s[i] - 'a']))
				continue ;
				f1 = 1 ;
			}
			//cout<<f1;
			int  j , k =s.size() -1  ;
			for( j = orig.size() -1 ; j>ind ; j-- , k--)
			{
				if(s[k] == orig[j] || (orig[j] == '?' && f[s[k] - 'a']))
				continue ;
			//	cout<<j;
				f1 = 1 ;
			}
		//	cout<<f1<<"\n" ;
			for(; i<=k ; i++)
			{
				if(f[s[i] - 'a'])
				f1= 1 ;
			}
		}

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

}


#include<bits/stdc++.h>
using namespace std;

string patt , org ;
int f[26] ;

int main()
{
	//scanf("%s%s" , &patt , &org) ;
	cin>>patt>>org ;
	for(int i =0 ; i<patt.size() ; i++)
	{
		//cout<<"AF";
		f[patt[i] - 'a'] = 1 ;
		//printf("%fas");
	}

	int t ;
	scanf("%d" , &t) ;

	while(t--)
	{
		string s ;
	//	scanf("%s" , &s) ;
		cin>>s ;

		int j = org.size()-1 ,  i  , f1 =0 ;

		for( i=0 ; i<s.size() ; i++)
	    {
	    	if(i == org.size())
	    	break ;

	    	if(s[i] == org[i] || (org[i] == '?' && f[s[i]-'a']))
	    	continue ;

	    	if(org[i] == '*')
	    	break ;

	    	f1 =1 ;
		}

		if(i<s.size()-1 &&  i == org.size())
		f1 = 1 ;
		if(i == s.size() && i < org.size() -1 )
		f1 = 1;

		int  k = s.size() - 1;

		for(; j>i && k>=i ; j-- , k--)
		{
			if(s[k] == org[j] || (org[j] == '?' && f[s[k] - 'a']))
			continue ;
			f1 = 1 ;

		}

		if(i < j)
		f1 = 1 ;

		for(; i<=k ;i++)
		{
			if(f[s[i] - 'a'])
			f1 = 1 ;
		}

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


#include<bits/stdc++.h>
using namespace std;

string patt , org ;
int f[26] ;

int main()
{
	//scanf("%s%s" , &patt , &org) ;
	cin>>patt>>org ;
	for(int i =0 ; i<patt.size() ; i++)
	{
		//cout<<"AF";
		f[patt[i] - 'a'] = 1 ;
		//printf("%fas");
	}

	int t ;
	scanf("%d" , &t) ;

	while(t--)
	{
		string s ;
	//	scanf("%s" , &s) ;
		cin>>s ;

		int j = org.size()-1 ,  i  , f1 =0 ;

		for( i=0 ; i<s.size() ; i++)
	    {
	    	if(i == org.size())
	    	break ;

	    	if(s[i] == org[i] || (org[i] == '?' && f[s[i]-'a']))
	    	continue ;

	    	if(org[i] == '*')
	    	break ;

	    	f1 =1 ;
		}

		if(i<s.size() &&  i == org.size())
		f1 = 1 ;
		if(i == s.size() && i < org.size()  )
		f1 = 1;

		int  k = s.size() - 1;

		for(; j>i && k>=i ; j-- , k--)
		{
			if(s[k] == org[j] || (org[j] == '?' && f[s[k] - 'a']))
			continue ;
			f1 = 1 ;

		}

		if(i < j)
		f1 = 1 ;

		for(; i<=k ;i++)
		{
			if(f[s[i] - 'a'])
			f1 = 1 ;
		}

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


#include <bits/stdc++.h>
using namespace std;
long long n,k,ss;
map<char,int>f;
string s1,s2,s;
main ()
{
	cin>>s2;

	for (int i=0; i<s2.size(); i++)
		f[s2[i]]=1;

	cin>>s1;

	cin>>n;

	for (int i=1; i<=n; i++)
	{
		cin>>s;

		int x=0,r=0;
		ss=0;

		for (int j=0; j<s.size(); j++)
		{
			if (s1[x]=='*' && r==0) r=1;

			if (s1[x]=='*' && s1.size()==s.size()+1)
			{
				r=0;
				x++;
			}

			if (r)
			{

				if (f[s[j]])
				{
					cout<<"NO"<<endl; ss=1;
					break;
				}

				if (r==s.size()-s1.size()+1) r=-1,x++;
				r++;
				continue;
			}

			if (r) continue;

			if ('a'<=s1[x] && s1[x]<='z')
			{
				if (s1[x]==s[j]) x++;
						else
				{
					cout<<"NO"<<endl; ss=1;
					break;
				}

				continue;
			}

			if (s1[x]=='?')
			{
				if (f[s[j]]) x++;
					else
				{
					cout<<"NO"<<endl; ss=1;
					break;
				}

				continue;
			}
		}

		if (!ss) cout<<"YES"<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
long long n,k,ss,Z;
map<char,int>f;
string s1,s2,s;
main ()
{
	cin>>s2;

	for (int i=0; i<s2.size(); i++)
		f[s2[i]]=1;

	cin>>s1;

	for (int i=0; i<s1.size(); i++)
		if (s1[i]=='*') Z=1;

	cin>>n;

	for (int i=1; i<=n; i++)
	{
		cin>>s;

		int x=0,r=0;
		ss=0;

		for (int j=0; j<s.size(); j++)
		{
			if (s1[x]=='*' && r==0) r=1;

			if (s1[x]=='*' && s1.size()==s.size()+1)
			{
				r=0;
				x++;
			}

			if (r)
			{
				if (f[s[j]])
				{
					cout<<"NO"<<endl;
					ss=1;
					break;
				}

				if (r==s.size()-s1.size()+1) r=-1,x++;
				r++;
				continue;
			}

			if (r) continue;

			if ('a'<=s1[x] && s1[x]<='z')
			{
				if (s1[x]==s[j]) x++;
						else
				{
					cout<<"NO"<<endl;
					ss=1;
					break;
				}

				continue;
			}

			if (s1[x]=='?')
			{
				if (f[s[j]]) x++;
					else
				{
					cout<<"NO"<<endl;
					ss=1;
					break;
				}

				continue;
			}
		}

	//	for (int j=0; j<s1.size(); j++)
		//	cout<<F[j]<<" ";
	//	cout<<endl;

		if (!ss && !Z && s1.size()!=s.size()) cout<<"NO"<<endl;
			else
		if (!ss && s1.size()<=x+1) cout<<"YES"<<endl;
			else
		if (!ss) cout<<"NO"<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
long long n,k,ss;
map<char,int>f;
string s1,s2,s;
main ()
{
	cin>>s2;

	for (int i=0; i<s2.size(); i++)
		f[s2[i]]=1;

	cin>>s1;

	cin>>n;

	for (int i=1; i<=n; i++)
	{
		cin>>s;

		int x=0,r=0;
		ss=0;

		for (int j=0; j<s.size(); j++)
		{
			if (s1[x]=='*' && r==0) r=1;

			if (s1[x]=='*' && s1.size()==s.size()+1)
			{
				r=0;
				x++;
			}

			if (r)
			{

				if (f[s[j]])
				{
					cout<<"NO"<<endl; ss=1;
					break;
				}

				if (r==s.size()-s1.size()+1) r=-1,x++;
				r++;
				continue;
			}

			if (r) continue;

			if ('a'<=s1[x] && s1[x]<='z')
			{
				if (s1[x]==s[j]) x++;
						else
				{
					cout<<"NO"<<endl; ss=1;
					break;
				}

				continue;
			}

			if (s1[x]=='?')
			{
				if (f[s[j]]) x++;
					else
				{
					cout<<"NO"<<endl; ss=1;
					break;
				}

				continue;
			}
		}

		if (!ss && s1.size()==x) cout<<"YES"<<endl;
					        else
		if (!ss) cout<<"NO"<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
long long n,k,ss;
map<char,int>f;
string s1,s2,s;
main ()
{
	cin>>s2;

	for (int i=0; i<s2.size(); i++)
		f[s2[i]]=1;

	cin>>s1;

	cin>>n;

	for (int i=1; i<=n; i++)
	{
		cin>>s;

		int x=0,r=0;
		ss=0;

		for (int j=0; j<s.size(); j++)
		{
			if (s1[x]=='*') r=1;

			if (r)
			{
				if (f[s[j]])
				{
					cout<<"NO"<<endl; ss=1;
					break;
				}

				if (r+1==s.size()-s1.size()) r=-1;
				r++;
				continue;
			}

			if (r) continue;

			if ('a'<=s1[x] && s1[x]<='z')
			{
				if (s1[x]==s[j]) x++;
						else
				{
					cout<<"NO"<<endl; ss=1;
					break;
				}

				continue;
			}

			if (s1[x]=='?')
			{
				if (f[s[j]]) x++;
					else
				{
					cout<<"NO"<<endl; ss=1;
					break;
				}

				continue;
			}
		}

		if (!ss) cout<<"YES"<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
long long n,k,ss,Z;
map<char,int>f;
string s1,s2,s;
main ()
{
	cin>>s2;

	for (int i=0; i<s2.size(); i++)
		f[s2[i]]=1;

	cin>>s1;

	for (int i=0; i<s1.size(); i++)
		if (s1[i]=='*') Z=1;

	cin>>n;

	for (int i=1; i<=n; i++)
	{
		cin>>s;

		int x=0,r=0;
		ss=0;

		for (int j=0; j<s.size(); j++)
		{
			if (s1[x]=='*' && r==0) r=1;

			if (s1[x]=='*' && s1.size()==s.size()+1)
			{
				r=0;
				x++;
			}

			if (r)
			{
				if (f[s[j]])
				{
					cout<<"NO"<<endl;
					ss=1;
					break;
				}

				if (r==s.size()-s1.size()+1) r=-1,x++;
				r++;
				continue;
			}

			if (r) continue;

			if ('a'<=s1[x] && s1[x]<='z')
			{
				if (s1[x]==s[j]) x++;
						else
				{
					cout<<"NO"<<endl;
					ss=1;
					break;
				}

				continue;
			}

			if (s1[x]=='?')
			{
				if (f[s[j]]) x++;
					else
				{
					cout<<"NO"<<endl;
					ss=1;
					break;
				}

				continue;
			}
		}

	//	for (int j=0; j<s1.size(); j++)
		//	cout<<F[j]<<" ";
	//	cout<<endl;

		if (!Z && s1.size()<s.size()) cout<<"NO"<<endl;
			else
		if (!ss && s1.size()<=x+1) cout<<"YES"<<endl;
			else
		if (!ss) cout<<"NO"<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
long long n,k,ss;
map<char,int>f;
string s1,s2,s;
main ()
{
	cin>>s2;

	for (int i=0; i<s2.size(); i++)
		f[s2[i]]=1;

	cin>>s1;

	cin>>n;

	for (int i=1; i<=n; i++)
	{
		cin>>s;

		int x=0,r=0;
		ss=0;

		for (int j=0; j<s.size(); j++)
		{
			if (s1[x]=='*' && r==0) r=1;

			if (s1[x]=='*' && s1.size()==s.size()+1)
			{
				r=0;
				x++;
			}

			if (r)
			{
				if (f[s[j]])
				{
					cout<<"NO"<<endl;
					ss=1;
					break;
				}

				if (r==s.size()-s1.size()+1) r=-1,x++;
				r++;
				continue;
			}

			if (r) continue;

			if ('a'<=s1[x] && s1[x]<='z')
			{
				if (s1[x]==s[j]) x++;
						else
				{
					cout<<"NO"<<endl;
					ss=1;
					break;
				}

				continue;
			}

			if (s1[x]=='?')
			{
				if (f[s[j]]) x++;
					else
				{
					cout<<"NO"<<endl;
					ss=1;
					break;
				}

				continue;
			}
		}

	//	for (int j=0; j<s1.size(); j++)
		//	cout<<F[j]<<" ";
	//	cout<<endl;

		if (!ss && s1.size()<=x+1) cout<<"YES"<<endl;
			else
		if (!ss) cout<<"NO"<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
long long n,k,ss,Z;
map<char,int>f;
string s1,s2,s;
main ()
{
	cin>>s2;

	for (int i=0; i<s2.size(); i++)
		f[s2[i]]=1;

	cin>>s1;

	for (int i=0; i<s1.size(); i++)
		if (s1[i]=='*') Z=1;

	cin>>n;

	for (int i=1; i<=n; i++)
	{
		cin>>s;

		int x=0,r=0;
		ss=0;

		for (int j=0; j<s.size(); j++)
		{
			if (s1[x]=='*' && r==0) r=1;

			if (s1[x]=='*' && s1.size()==s.size()+1)
			{
				r=0;
				x++;
			}

			if (r)
			{
				if (f[s[j]])
				{
					cout<<"NO"<<endl;
					ss=1;
					break;
				}

				if (r==s.size()-s1.size()+1) r=-1,x++;
				r++;
				continue;
			}

			if (r) continue;

			if ('a'<=s1[x] && s1[x]<='z')
			{
				if (s1[x]==s[j]) x++;
						else
				{
					cout<<"NO"<<endl;
					ss=1;
					break;
				}

				continue;
			}

			if (s1[x]=='?')
			{
				if (f[s[j]]) x++;
					else
				{
					cout<<"NO"<<endl;
					ss=1;
					break;
				}

				continue;
			}
		}

	//	for (int j=0; j<s1.size(); j++)
		//	cout<<F[j]<<" ";
	//	cout<<endl;

		if (!ss && !Z && s1.size()<s.size()) cout<<"NO"<<endl;
			else
		if (!ss && s1.size()<=x+1) cout<<"YES"<<endl;
			else
		if (!ss) cout<<"NO"<<endl;
	}
}