Ben's favourite game is osu redtea!
The game is simple: given a 3 letter sequence , output the longest word in the dictionary that contains as a substring. The game is played for rounds with the same dictionary, which contains words, none of which exceed 20 characters long.
Ben is, unfortunately, not great at the game, so he needs your help. Please write a program that will play the game for him!
Input Specification
The first line contains an integer representing the size of the dictionary, .
The next lines contain the words in the dictionary, consisting of lowercase alphabetic characters. None of the words will exceed 20 characters long.
The next line contains which represents the number of rounds being played .
The next lines contain , representing the 3 letter sequence. The letters will be lowercase alphabetic characters.
Output Specification
For each of the rounds, output the longest word containing the 3 letter sequence. If multiple valid words have the same length, output the lexicographically least word. If no valid word exists, output -1
.
Sample Input 1
5
boxes
more
moreover
layman
foregoes
3
ore
aym
meo
Sample Output 1
foregoes
layman
-1
Comments