CSES - E4590 2017 6 - Spell checker
  • 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 dd of valid words. When a word wiw_i s written, the program compares it to all words in the dictionary dd to determine the closest match. The closest match is the word in dd whose edit distance to wiw_i 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 nn, the number of words in dictionary dd. Next nn lines contain all words in dd in lexicographical order.

After the dictionary follows a line with single integer qq, the number of words to spell check. Next qq lines contain words wiw_i 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 eie_i and word rir_i, the edit distance between wiw_i and the closest match, and the closest match eie_i.

Limits

  • 1n41051 \le n \le 4\cdot10^5
  • 1length(si)321 \le \text{length}(s_i) \le 32
  • 1i=0nlength(si)51061 \le \sum_{i=0}^n\text{length}(s_i) \le 5\cdot10^6
  • 1q101 \le q \le 10

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