#include <bits/stdc++.h>
#define NMAX 100005
using namespace std;

inline void debugMode() {
    #ifndef ONLINE_JUDGE
    freopen("debug.in", "r", stdin);
    #endif // ONLINE_JUDGE
}

int N(char s){
    return s - 'a';
}

string S[30],a,A[NMAX];
bitset < NMAX > B;

int main()
{
    ios :: sync_with_stdio(false);
    debugMode();
    int n;


    for(int i = 0; i < 26; i++){
       getline(cin,a);
       for(auto const it : a){
        if(it == '-' || it == '.')
            S[i] = S[i] + it;
       }

    }

    cin >> n;
     getline(cin,a);
    for(int i = 1; i <= n; i++){
        getline(cin,a);
        for(auto const it : a){
                A[i] = A[i] + S[N(it)];

        }
    }

    int sol = 0,j,csol;

    for(int i = 1; i <= n; i++){
        csol = 1;
        if(B[i] == 0){
            B[i] = 1;
            for(int k = i + 1; k <= n; k++){
                if(A[i] == A[k]){
                    csol ++;
                    B[k] = 1;
                }
            }

        }
        sol = max(sol,csol);
    }
    cout << sol;

    return 0;
}