#000606

Lingvista

Mister S likes words, so he has invented his own language, which consists of N words. He wants to enrich the language by adding new words, where each word is obtained by appending or prepending letters to some of the already existing words.


Mister S has already come up with M new words. In order to test whether the words satisfy the (ap/pre)pending rule, he asks you to tell him for a given word w what is the longest word in his language which results in w by appending letters, and what is the longest word in his language which results in w by prepending letters.
If such a word does not exist in his languages, you should print "ne postoji" (without quotes).


InputThe first line of the standard input contains an integer N, which is the number of the words in the language. In the next N lines are given the words. The next line contains an integer M, which represents the number of new words. In the next M lines are given words which Mister S would like to add to the language. The words in the language and the new words are consisted of lower-case letters.

OutputFor every new word which Mister S would like to add to his language, you should print two space-separated words as described in the problem statement.

Constraints:
1 <= N,M <= 1000
In 80% of the test cases each word will contain at most 50 letters, while in the remaining 20% of the test cases each word will contain at most 1000 letters.



Input:
9
baba
deda
duks
erica
jedan
dan
kol
lac
skola
7
bababa
dedaujedan
dukserica
duks
jedan
kolac
skolarac


Output:
baba baba
deda jedan
duks erica
ne postoji ne postoji
ne postoji dan
kol lac
skola ne postoji


Explanation:
For instance, the word "skolarac" can be obtained by appending "rac" to the word "skola" , but we can not obtain the same word by prepending letters to some of the words in the language.

Submit solution

Coming later

The grading service will be connected in a later migration step. You can inspect the task and your previous results now.