//第二题详解
#include<iostream>
#include<string>
#include<vector>
using namespace std;

struct IPallow{
	int flag;  //1 allow or 0 deny;
	vector<int> ip;
	int mask;
};

vector<int> IpStrToIpInt(string ipstr)
{
	vector<int> ipint;
	int index=0;
	while(index!=string::npos)
	{
		index=ipstr.find('.');
		if(index==string::npos) {ipint.push_back(atoi(ipstr.c_str())); break;}
		ipint.push_back(atoi((ipstr.substr(0,index)).c_str()));
		ipstr=ipstr.substr(index+1,ipstr.length()-index-1);
	}

	return ipint;
}

vector<IPallow> StringtoIPallow(vector<string> list)
{
	vector<IPallow> iplist;
	string temp,allow,ipstr,maskstr,right;
	IPallow ip;
	int space,slash;
	for(int i=0;i<list.size();i++)
	{
		temp=list[i];
		space=temp.find(' ');
		allow=temp.substr(0,space);
		right=temp.substr(space+1,temp.length()-space);
		slash=right.find('/');
		if(slash!=string::npos)
		{
			ipstr=right.substr(0,slash);
			maskstr=right.substr(slash+1,right.length()-slash);
		}
		else
		{
			ipstr=right;
			maskstr="32";
		}
		if(allow=="allow") ip.flag=1;
		else ip.flag=0;
		ip.mask=atoi(maskstr.c_str());
		ip.ip=IpStrToIpInt(ipstr);
		iplist.push_back(ip);
	}

	return iplist;
}

void JudgeIP(vector<string> list,string q)
{
	vector<int> qin=IpStrToIpInt(q);
	vector<IPallow> iplist=StringtoIPallow(list);
	vector<int> temp;
	IPallow tempip;
	int mask;
	for(int i=0;i<iplist.size();i++)
	{
		temp=qin;
		tempip=iplist[i];
		mask=32-tempip.mask;
		if(mask<=8)
		{
			tempip.ip[3]=tempip.ip[3]>>mask;
			temp[3]=temp[3]>>mask;
			if(tempip.ip==temp) {
				if(tempip.flag)
					cout<<"Yes"<<endl;
				else cout<<"No"<<endl;
				return;
			}
			continue;
		}
		if(mask<=16)
		{
			tempip.ip[3]=0;  temp[3]=0;
			tempip.ip[2]=tempip.ip[2]>>mask-8;
			temp[2]=temp[2]>>mask-8;
			if(tempip.ip==temp) {
				if(tempip.flag)
					cout<<"Yes"<<endl;
				else cout<<"No"<<endl;
				return;
			}
			continue;
		}
		if(mask<=24)
		{
			tempip.ip[3]=0;  temp[3]=0;
			tempip.ip[2]=0;  temp[2]=0;
			tempip.ip[1]=tempip.ip[1]>>mask-16;
			temp[1]=temp[1]>>mask-16;
			if(tempip.ip==temp) {
				if(tempip.flag)
					cout<<"Yes"<<endl;
				else cout<<"No"<<endl;
				return;
			}
			continue;
		}
		if(mask<=32)
		{
			tempip.ip[3]=0; temp[3]=0;
			tempip.ip[2]=0; temp[2]=0;
			tempip.ip[1]=0; temp[1]=0;
			tempip.ip[0]=tempip.ip[0]>>mask-24; 
			temp[0]=temp[0]>>mask-24;
			if(tempip.ip==temp) {
				if(tempip.flag)
					cout<<"Yes"<<endl;
				else cout<<"No"<<endl;
				return;
			}
			continue;								
		}
	}
	cout<<"No"<<endl;
	return;
}

int main(){
	int n,m;
	cin>>n>>m;
	vector<string> list,qu;
	string temp;
	getchar();
	for(int i=0;i<n;i++){ getline(cin,temp); list.push_back(temp);}
	for(int i=0;i<m;i++){ getline(cin,temp); qu.push_back(temp);}

	for(int i=0;i<m;i++){ JudgeIP(list,qu[i]);}
	system("pause");
	return 0;
}