ZigZag

Given K words and N letters, output for each letter the word starting with it that has been used fewest times, breaking ties alphabetically.

Medium4SortingHash mapImplementationGreedyInterviewNo attempts yetTime limit2sMemory limit64 MB

Problem

Zig and Zag play a word game. Zig says one lowercase letter, and Zag answers with a word that starts with that letter. The word must come from a fixed word list, and among the words on the list that start with that letter, Zag says the one he has said the fewest times so far. If several words tie, Zag says the one that comes first in alphabetical order. For every letter Zig says, a word is always available.

You are given a list of KK distinct words and the NN letters Zig says. Write a program that prints the NN words Zag says, in order.

Input

The first line contains KK (1K1000001 \le K \le 100\,000) and NN (1N1000001 \le N \le 100\,000).

Each of the next KK lines contains one word, a string of lowercase English letters of length at most 2121.

Each of the next NN lines contains one lowercase English letter that Zig says.

Output

Print NN lines. Line ii contains the word Zag says in answer to the ii-th letter.