#include <bits/stdc++.h> using namespace std; #define ios ios_base::sync_with_stdio(false);cin.tie(0); #define setnow clock_t tStart=clock(); #define time (double)(clock() - tStart)/CLOCKS_PER_SEC; //#define setin(x) ifstream cin(x); //#define setout(x) ofstream cout(x); typedef long long ll; typedef long long int lli; typedef pair < int, int> dbl; const int maxInt = 1e9*2; const lli maxLong = 1e18*2; map <char, string> alph; map <string, int> nbr; int main(){ //ifstream cin("input.in"); int ans = 0; for(int i=0;i<26;i++){ char ch; string str; cin >> ch >> str; alph[ch] = str; } int n; cin >> n; for(int i=0;i<n;i++){ string str; cin >> str; string repr=""; for(int j=0;j<str.size();j++) repr+=alph[str[j]]; nbr[repr]++; ans = max(ans, nbr[repr]); } cout << ans << endl; }