#include <bits/stdc++.h>

using namespace std;

const int SIGMA = 26;

string rep[SIGMA];

const int P = 1e9 + 7;

unordered_map<long long, int>ap;

long long calc(const string &s) {
	long long val = 1;

	for (int i = 0; i < s.size(); ++i)
		for (int j = 0; j < rep[s[i] - 'a'].size(); ++j)
			val = val * P + rep[s[i] - 'a'][j];

	return val;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("cutit.in", "r", stdin);
#endif // ONLINE_JUDGE

	ios::sync_with_stdio(0);

	for (int i = 0; i < SIGMA; ++i) {
		char ch;
		cin >> ch;
		cin >> rep[ch - 'a'];
	}

	int n;
	string s;
	cin >> n;

	for (int i = 0; i < n; ++i) {
		cin >> s;
		ap[calc(s)]++;
	}

	int ans = 0;

	for (auto i : ap)
		ans = max(ans, i.second);

	cout << ans;

	return 0;
}