- Time limit: 3.00 s
- Memory limit: 512 MB
Teemu has used text editor Sentence and especially its spell checker. Unfortunately, the last update broke the spell checker and Teemu is quite a bad writer. To add insult to injury, Teemu needs to return a literature analysis tomorrow without any spelling mistakes or he will fail the course.
The spell checker works by having a dictionary of valid words. When a word s written, the program compares it to all words in the dictionary to determine the closest match. The closest match is the word in whose edit distance to is smallest. In case of ties with edit distance, the word which is lexicographically smallest is chosen as the closest match.
Help Teemu by writing him a spell checker.
For a description of edit distance, see this homework task.
Input
The first line of input consists of single integer , the number of words in dictionary . Next lines contain all words in in lexicographical order.
After the dictionary follows a line with single integer , the number of words to spell check. Next lines contain words to spell check.
Each word in the dictionary and being checked consists of characters a-z.
Output
Output single line for each word being spell checked. The line shall contain integer and word , the edit distance between and the closest match, and the closest match .
Limits
Example
Input:
6 car cat feather weather wether whether 5 car bat cas teather weater
Output:
0 car 1 cat 1 car 1 feather 1 weather