#P7534. Ticket Machine Keyboard Search
Ticket Machine Keyboard Search
Ticket Machine Keyboard Search
At the train station, when using the automatic ticket machine, you can search for your destination city by clicking letters on the screen's keyboard. The keyboard is modeled as a $4 \times 8$ matrix of characters:
Row1: A B C D E F G H Row2: I J K L M N O P Row3: Q R S T U V W X Row4: Y Z # @ & * % !
Currently, there are $N$ city names displayed. After you input an initial string by clicking some letters, the machine filters and only displays the cities whose names have that initial string as a prefix. Moreover, for each key on the keyboard, if appending its character to the initial string does not yield a prefix of any of the remaining city names, then that character is replaced by $\texttt{*}$ in the final keyboard state.
Your task is to output the final state of the keyboard after the initial string is entered.
inputFormat
The first line contains a positive integer $N$, the number of cities. The following $N$ lines each contain a city name (a non-empty string). The $(N+2)$-th line contains a non-empty initial string.
outputFormat
Output the final state of the keyboard in 4 lines. Each line should contain exactly 8 characters. For any key where appending its character to the initial string does not match as a prefix to any city (after filtering), output an asterisk ($\texttt{*}$) instead of the original character.
sample
3
BEIJING
BERLIN
BOSTON
B
****E***
*****O
</p>