/*input
a .-
b -...
c -.-.
d -..
e .
f ..-.
g --.
h ....
i ..
j .---
k -.-
l .-..
m --
n -.
o ---
p .--.
q --.-
r .-.
s ...
t -
u ..-
v ...-
w .--
x -..-
y -.--
z --..
5
ca
nna
abc
nnet
cat
*/
#include <bits/stdc++.h>
#define fastIo ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define sz size
#define pb push_back
#define mp make_pair
using namespace std;

//#define LOCAL
#ifdef LOCAL
	#define DEBUG(x) do { cout << #x << ": " << x << '\n'; } while (0)
#else
	#define DEBUG(x) 
#endif

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

map<char, string> morse;
map<string, int> cnt;

int main(){
	fastIo;

	string s;
	char ch;
	for(int i = 0; i < 26; i++){
		cin >> ch >> s;
		morse[ch] = s;
	}

	int n;
	cin >> n;

	int ans = 0;
	for(int i = 0; i < n; i++){
		cin >> s;
		string enc = "";
		for(int j = 0; j < (int)s.sz(); j++){
			enc += morse[s[j]];
		}
		cnt[enc]++;
		if(cnt[enc] > ans) ans = cnt[enc];
	}

	cout << ans << '\n';

	return 0;
}