#include using namespace std; int main() { map Map; for(int i = 0; i < 26; ++i) { char c; string s; cin >> c >> s; Map[c] = s; } map Cnt; int n; cin >> n; while(n--) { string small, big; cin >> small; for(auto c : small) big += Map[c]; // cerr << big << Cnt[big] << endl; Cnt[big] += 1; } int best = 0; for(auto p : Cnt) best = max(best, p.second); if(best == 0) cout << -1 << endl; else cout << best << endl; return 0; }