#include <bits/stdc++.h>
#include <unordered_map>
#define bug cout << "***************" << endl
#define fuck(x) cout << #x << " -> " << x << endl
#define endl '\n'
#define int long long
using namespace std;
constexpr int N = 1e6 + 10, inf = 0x3f3f3f3f;
int f[N];
unordered_map<string, int> mp;
int cnt = 0;
int find(int x)
{
if (f[x] != x)
f[x] = find(f[x]);
return f[x];
}
int get(string x)
{
if (mp.count(x) == 0)
{
mp[x] = ++cnt;
}
return mp[x];
}
void solve()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
string s;
cin >> s;
}
for (int i = 1; i <= n; i++)
{
f[i] = i;
}
for (int i = 1; i <= m; i++)
{
string s1, s2;
cin >> s1 >> s2;
int pa = find(get(s1)), pb = find(get(s2));
f[pa] = pb;
}
int k;
cin >> k;
while (k--)
{
string s1, s2;
cin >> s1 >> s2;
int pa = find(get(s1)), pb = find(get(s2));
if (pa == pb)
{
cout << "Yes." << endl;
}
else
{
cout << "No." << endl;
}
}
}
signed main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T = 1;
while (T--)
{
solve();
}
return 0;
}