Under construction

Still being built. Things may change

Ticket machine keyboard

Interview

Time limit1sMemory limit32 MB

Summary
Given destination names and a pressed prefix, mark on a 4x8 grid every letter that can immediately follow the prefix in some name.
Level

Easy3 of 10

Topics
String, Simulation, Implementation, Hash map
Solved
No attempts yet

Problem

A ticket machine is a device similar to an ATM, installed at train stations to make buying tickets easier. The first step in buying a ticket is choosing the destination. The destination is one of NN names prepared in advance, and you choose it by pressing the name one letter at a time. Each extra letter reduces the number of destinations that are still possible.

The keyboard on the screen has 4 rows of 8 keys. The letters A to Z sit in order starting from the fourth key of the first row, and the remaining 6 keys are always empty. An empty key and a letter that cannot be pressed are both written as the character *. The initial appearance is shown below.

***ABCDE
FGHIJKLM
NOPQRSTU
VWXYZ***

After each letter the keyboard changes. Only the letters that can be pressed next remain, based on the destinations that are still possible, and every other letter turns into *.

Given NN destination names and the letters pressed so far, print the appearance of the keyboard just before the next letter is pressed.

Input

The first line contains the number of destinations NN. (1≤N≤501 \le N \le 50)

Each of the next NN lines contains one destination name. A name consists of uppercase English letters only and has at most 100100 characters. The same name may appear more than once.

The last line contains the string SS pressed so far. SS consists of uppercase English letters only, has between 11 and 9999 characters, and is a proper prefix of at least one destination name, so a full name is never given.

Output

Print the keyboard as 4 lines of 8 characters. For every name that starts with SS, keep the letter that follows SS in its own cell, and print * in every other cell.

A name whose length equals the length of SS has no next letter, so it keeps no cell.

Hint

In the first example, after ZA is pressed, the third letter is G for a ticket to ZAGREB, D for ZADAR and B for ZABOK.

Examples3

  1. Example 1

    Input
    4
    ZAGREB
    SISAK
    ZADAR
    ZABOK
    ZA
    
    Expected output
    ****B*D*
    *G******
    ********
    ********
    
  2. Example 2

    Input
    4
    SPLIT
    VINKOVCI
    NOVSKA
    RIJEKA
    VINKO
    
    Expected output
    ********
    ********
    ********
    V*******
    
  3. Example 3

    Input
    4
    AAAABCD
    AAAABCA
    AAAACDE
    AAAAAAA
    AAAA
    
    Expected output
    ***ABC**
    ********
    ********
    ********