#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< pair, int > MP; for( auto str : v[i] ) { int k1 = 0, k2 = 0, p1 = 1, p2 = 1; for( auto ch : str ) { k1 = ( k1 + p1*( (ch == '.') + 1 ) ) % MOD1; k2 = ( k2 + p2*( (ch == '.') + 1 ) ) % MOD2; p1 = (p1*3) % MOD1; p2 = (p2*3) % MOD2; } MP[ {k1,k2} ]++; Ans = max( Ans, MP[ {k1,k2} ] ); } } if( Ans < 2 ) cout << "1-\n"; else cout << Ans << '\n'; return 0; }