#include <bits/stdc++.h>
using namespace std;
int main() {
int N,M;
string s1,s2;
map<string,vector<string>>mp;
cin>>N>>M;
for(int i = 0;i<N;i++)
{
cin>>s1>>s2;
mp[s1].push_back(s2);
}
int K;
string s;
vector<string>v;
for(int i = 0;i<M;i++)
{
cin>>K;
v.clear();
for(int j = 0;j<K;j++)
{
cin>>s;
v.push_back(s);
}
int flag = 0;
for(int j = 0;j<K;j++)
{
if(mp.count(v[j]))
{
for(int k = 0;k<K;k++)
{
for(string s:mp[v[j]])
{
if(v[k] == s)
{
cout<<"No"<<endl;
flag = 1;
break;
}
}
if(flag) break;
}
if(flag) break;
}
}
if(!flag) cout<<"Yes"<<endl;
}
return 0;
}
/*
*
6 3
20001 20002
20003 20004
20005 20006
20003 20001
20005 20004
20004 20006
4 00001 20004 00002 20003
5 98823 20002 20003 20006 10010
3 12345 67890 23333
6 1
20001 20002
20003 20004
20005 20006
20003 20001
20005 20004
20004 20006
2 20001 20002
*/