#include using namespace std; const int NMAX = 100000; const int MOD1 = 666013; const int MOD2 = 696961; const int LGMAX = 4 * NMAX + 5; const int SIGMA = 26; map LET; int N, Ans = 0; vector < string > v[LGMAX]; int main() { for( int i = 1; i <= SIGMA; ++i ) { char ch; string s; cin >> ch >> s; LET[ch] = s; } cin >> N; for( int i = 1; i<= N; ++i ) { string s, line; cin >> s; for( auto ch : s ) { line += LET[ch]; } v[ line.size() ].push_back( line ); } for( int i = 1; i <= LGMAX; ++i ) { map< string, int > MP; for( auto str : v[i] ) { MP[str]++; Ans = max( Ans, MP[ str ] ); } } if( Ans < 1 ) cout << "1-\n"; else cout << Ans << '\n'; return 0; }