#include <iostream>
#include <cstring>
using std::cin;
using std::cout;
int main() {
int n, m;
cin >> n >> m;
bool G[26][26];
while (n--) {
char a, b;
cin >> a >> b;
G[a - 'a'][b - 'a'] = true;
}
for (int k = 0; k < 26; k++)
for (int i = 0; i < 26; i++)
for (int j = 0; j < 26; j++)
if (G[i][k] & G[k][j])
G[i][j] = true;
while (m--) {
char s[51], t[51];
cin >> s >> t;
int len = strlen(s);
if (len != strlen(t)) {
cout << "no\n";
continue;
}
for (int i = 0; i < len; i++)
if (s[i] != t[i] && !G[ s[i] - 'a' ][ t[i] - 'a' ]) {
cout << "no\n";
goto noans;
}
cout << "yes\n";
noans:;
}
return 0;
}