#include using namespace std ; vector morse ; map H ; int main() { //freopen ("input", "r", stdin) ; int t = 26 ; while (t --) { char c ; string x ; cin >> c >> x ; morse.push_back (x) ; } int n ; cin >> n ; while (n --) { string y ; string decode = "" ; cin >> y ; for (auto x : y) { decode += morse [x-'a'] ; } H [decode] += 1 ; } int best = 0 ; for (auto y : H) { best = max (best, y.second) ; } if (best == 0 or best == 1) { cout << -1 ; return 0 ; } cout << best ; return 0 ; }