#include using namespace std; string m[26]; map H; string toMorse(string word) { string ret = ""; for (int i = 0; i < (int)word.size(); i++) ret = ret + m[word[i]-'a']; return ret; } int main() { //freopen("input","r",stdin); for (int i = 0; i < 26; i++) { string s1,s2; cin >> s1 >> s2; m[s1[0]-'a'] = s2; } int n; cin >> n; int Sol = 0; for (int i = 1; i <= n; i++) { string s; cin >> s; string tm = toMorse(s); H[tm]++; Sol = max(Sol,H[tm]); } if (Sol > 1) cout << Sol; else cout << -1; }