#include <stdio.h>
#include <string.h>
#include <algorithm>

#define SYMBOLS 26
#define MODULO1 1999999973
#define MODULO2 1999999943


char morse[26][10], word[200001], buffer[1000000];
struct HASHES {
    int hash1, hash2;
} ;
HASHES hashes[200001];

int doHash(int modulo, char* word) {
    long long result = 0;
    long long multiplier = 1;

    while (*word != 0) {
        result = (result + (*word) * multiplier % modulo) % modulo;
        multiplier = (multiplier * SYMBOLS) % modulo;
        word += 1;
    }

    return result;
}

bool comparator(const HASHES &a, const HASHES &b) {
    if (a.hash1 == b.hash1) {
        return a.hash2 < b.hash2;
    }

    return a.hash1 < b.hash1;
}

int main() {
    char *p;
    int it, noWords, current = 1, result = 0;

    //freopen("in.txt", "r", stdin);

    for(it = 0; it < 26; ++it) {
        fgets(buffer, 20, stdin);
        strcpy(morse[it], buffer + 2);
        morse[it][strlen(morse[it]) - 1] = 0;
    }

    fgets(buffer, 100, stdin);
    sscanf(buffer, "%d", &noWords);
    for (it = 0; it < noWords; ++it) {
        fgets(word, 200000, stdin);
        buffer[0] = 0;
        for (p = word; *p && ((*p) != '\n'); ++p) {
            strcat(buffer, morse[*p - 'a']);
        }

        hashes[it].hash1 = doHash(MODULO1, buffer);
        hashes[it].hash2 = doHash(MODULO2, buffer);
    }

    std::sort(hashes, hashes + noWords, comparator);
    for (it = 1; it < noWords; ++it) {
        if (hashes[it - 1].hash1 == hashes[it].hash1 &&
                hashes[it - 1].hash2 == hashes[it].hash2) {
                    ++current;
                }
        else {
            if (current > result) result = current;
            current = 1;
        }
    }
    if (current > result) result = current;
    printf("%d", result);

    return 0;
}