Sanggeun is crazy about the board game "Boggle". Boggle lays out 16 lettered dice in a 4×4 grid, and players hunt for as many words as they can inside that grid.
Sanggeun has never once beaten his wife at Boggle. Every loss costs him a chore, taking out the trash or washing the dishes. This time he wants to win with a program.
A word is built by stepping from one cell to a neighboring cell, horizontally, vertically, or diagonally. One cell can be used at most once inside a single word. Only a word listed in the dictionary counts as a valid word.
The score of a word depends on its length. A word of 1 or 2 letters is worth 0 points, 3 or 4 letters is worth 1 point, 5 letters is worth 2 points, 6 letters is worth 3 points, 7 letters is worth 5 points, and 8 letters is worth 11 points. The score of a board is the sum of the scores of the words found on it.
You are given the dictionary and the Boggle boards. Write a program that finds the highest score obtainable on each board, the longest word, and the number of words found.
The first line contains the number of words in the dictionary, w. (1<w<300,000)
Each of the next w lines contains one word. A word consists of uppercase letters only and is at most 8 letters long. A single blank line follows the dictionary.
The next line contains the number of boards, b. (1<b<30) Each board is given as 4 lines of 4 uppercase letters, and a single blank line separates one board from the next.
For each board print the highest score obtainable, the longest word, and the number of words found, separated by spaces, on one line.
A word found along several paths on the same board counts once. If several words tie for the longest, print the one that comes first in alphabetical order. Only boards with at least one findable word are given as input.