#include<bits/stdc++.h>

using namespace std;

//ifstream fin("a.in");
//ofstream fout("a.out");

string sir[30],a;
int n;
char ch;

unordered_map<string, int> dictionar;


int main()
{
    int sol = -1;
    for(int i = 1; i <= 26; i++)
    {
        cin >> ch >> sir[i];
    }
    //getline(fin,a);
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a;
        int lung = a.length();
        string word = "";
        for(int j = 0; j < lung; j++)
        {
            word = word + sir[a[j]-'a' + 1];
        }
        dictionar[word]++;
        sol = max(dictionar[word],sol);
    }
    cout << sol<<"\n";

}