#include <bits/stdc++.h>
#include <map>
using namespace std;
int n, m;
map<string, string> fa[20005];
string find(string s) {
if (fa[s] == s) return fa[s];
return s = find(fa[s]);
}
void merge(string x, string y) {
x = find(x);
y = find(y);
if (x != y) {
fa[y] = x;
}
}
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
string name;
cin >> name;
fa[name] = name;
}
for (int i = 0; i < m; i++) {
string x, y;
cin >> x >> y;
merge(x, y);
}
int k;
cin >> k;
for (int i = 0; i < k; i++) {
string x, y;
cin >> x >> y;
if (find(x) == find(y)) cout << "Yes." << endl;
else cout << "No." << endl;
}
return 0;
}