12060 - EECS_2018_MID1-2   

Description

Given a string A and n strings B1, B2, B3, ..., Bn, count the number of occurrences of string A in each of B1, B2, B3, … , and print the maximum number of occurrences. The string A contains only digits, and the strings B1, B2, ..., Bn contain only digits or '#'.  The character '#' is a wildcard character that can match any single digit (0-9).

 
For example, if A is "50", n = 3, and the n strings are
"5005"
"055050"
"5#50#0"
then your answer should be 3 because the maximum number of occurrence is 3: "50" appears in "5005" one time, in "055050" two times, and in "5#50#0" three times ("5#", "50", "#0" all match "50"). 

Note that if A is "99" and B1 is "9999", the number of occurrences of A in B1 is counted as 3.

Input

The first line of the input is the string A (0 < length of A <= 4). The second line is n (1<n<10).

For the next n lines, each line contains a string Bi (length of A < length of Bi < 9).

Output

The maximum number of occurrences of A appears in B1, B2, ..., Bn taking the wildcard character into consideration. Note that you need to print '\n' at the end of the output.

Sample Input  Download

Sample Output  Download

Tags




Discuss