Boggle
I am sure, you are a big fan of the board game "Boggle". Don't worry if you are not familiar with the rules, I will explain them to you. A Boggle is a grid of letters where your job is to find as many words as you can. If I play Boggle with (or against) my wife, she always wins — the loser (that’s me) then always has to do all these little jobs like to take out the trash. So, please help me to win again.
Words in a Boggle can be constructed from adjacent letters (i.e. horizontally, vertically and diagonally), but the same dice may only be used once in a word. The words have to be listed in our dictionary to be valid.
Words with or letters count point, words with letters points, letters points, letters points. letter words will give points. If you find more than one word (and I hope you do), points will be summed up to form your score.
Input
There is only one test case. The first line contains the number of words in the dictionary. Then follow lines, each containing one word. Words consist of up to upper case letters ('A' — 'Z'). After the dictionary specification, there is a blank line. Then follows the number of Boggle boards in one line. Each boggle is given as a grid of upper case letters in four lines. Boggles are separated by blank lines.
Output
For each boggle, print one line containing the maximal possible score, the longest word and number of found words. Words that are twice (or more often) in one Boggle, only count once. If there is more than one longest word, print the lexicographically smallest one. You may safely assume that there is at least one valid word in each Boggle.