#include<bits/stdc++.h>
using namespace std;
struct em{
string name;
int f;
}a[20010];
int find(int x){
if(a[x].f!=x)
a[x].f=find(a[x].f);
return a[x].f;
}
int main() {
int n,i,m,az,o1,o2;
string t,y;
cin>>n>>m;
for(i=1;i<=n;i++){
cin>>a[i].name ;a[i].f=i;
}
for(i=1;i<=m;i++){
cin>>t>>y;
for(o1=1;o1<=n;o1++)
if(a[o1].name==t)
break;
for(o2=1;o2<=n;o2++)
if(a[o2].name ==y)
break;
a[o1].f=a[o2].f;
}
cin>>az;
for(i=1;i<=az;i++)
{
cin>>t>>y;
for(o1=1;o1<=n;o1++)
if(a[o1].name ==t)
break;
for(o2=1;o2<=n;o2++)
if(a[o2].name ==y)
break;
if(find(o1)==find(o2))
cout<<"Yes.";
else
cout<<"No.";
cout<<endl;
}
return 0;
}