Spell#5286

Spell

2 seconds
64 megabytes
Very hard

Troll Vol'jin is on a quest to discover the most effective healing spells. He aims to blend ancient spells with contemporary healing magic research so that his spells heal faster than any known ones. Vol'jin has selected spells from ancient texts. He wants his new spell to be a substring of all these ancient spells. This means that whenever any of the ancient spells are recited, Vol'jin's new spell will also be recited. To simplify recording, the troll encodes spells using lowercase Latin letters. There may be multiple spells that are substrings of all the chosen ancient spells, so Vol'jin doesn't require you to find them all. Instead, he asks you to provide certain spells based on their lexicographical order.

Your task is to find the spells requested by Vol'jin.

Input

The first line of the input contains a single number (1 \leq N \leq 20), representing the number of ancient spells Vol'jin has selected. The next lines describe each spell as a string of lowercase Latin letters. The total length of all spell descriptions does not exceed 10^5. Then follows a number , indicating how many spells Vol'jin wants to retrieve. The next lines each contain one number, the lexicographical position (from ) of the spell Vol'jin wishes to obtain. It is guaranteed that this position does not exceed the total number of valid spells.

Output

For each request, output the corresponding spell on a separate line. It is guaranteed that the total length of all output spells will not exceed 10^5.

Examples

Example 1

Loading
Loading