Car Game

No attempts yetTime limit2sMemory limit256 MB

Problem

A long drive gets boring, and one cure is a word game. A round starts when someone reads out loud the three letters on the license plate of an oncoming car. The first player to say a word that contains those three letters in the same order wins the round, and whoever has won the most rounds when the car stops wins the game. The three letters do not have to sit next to each other in the word, only in that order.

You lost badly on the last road trip. This time you prepare in advance. For each set of three letters, find the first word in a dictionary that contains those letters in the same order.

Input

The first line contains the number of words in the dictionary NN and the number of license plates to handle MM (1N50001 \le N \le 5000, 1M100001 \le M \le 10000).

Each of the next NN lines contains one dictionary word, a string of at most 100 lower case English letters. A word printed on an earlier line comes earlier in the dictionary.

Each of the next MM lines contains one license plate, a string of three upper case English letters.

Output

Print one line for each license plate. Ignoring letter case, print the first word in the dictionary that contains the three plate letters in the same order. If no such word exists, print No valid word.