Lazy Telegraph

Time limit1sMemory limit128 MB

Problem

Mirko found a telegraph in his attic and wants to send messages to his friend Slavko. The telegraph sends strings made of dots (.) and dashes (-). Sending one dot requires holding the key for 1 second, and sending one dash requires holding it for 2 seconds.

Because Mirko is very lazy, he may change some symbols in each word before sending it, trying to make the transmission time as short as possible.

Mirko and Slavko do not know Morse code, so they made a dictionary containing every word they may ever need. When Mirko sends an original word, Slavko must be able to recover that original word uniquely by the following rule.

Slavko considers only dictionary words with the same length as the original word. Among them, he chooses a word that differs from the sent string in the smallest number of symbols. There must be exactly one word with that minimum difference, and it must be the original word.

Given the dictionary and the text Mirko wants to send, find the minimum total time needed to send all words so that every word can be decoded uniquely. Spaces between words do not need to be sent.

Input

The first line contains the number of words in the dictionary, N. (1 <= N <= 2000)

Each of the next N lines contains one dictionary word. Each word has length at most 12 and consists only of . and -.

The next line contains the number of words Mirko wants to send, L. (1 <= L <= 10000)

Each of the next L lines contains one word Mirko wants to send. Every such word is in the dictionary.

Output

Print the minimum time needed to send the message so that Slavko can decode every word uniquely.

Hint

In the first visible test, Mirko can send .... instead of the first word, taking 4 seconds, and -..- instead of the second word, taking 6 more seconds. The total is therefore 10 seconds.