
Figure F.1: Sample Input 1. An example virtual keyboard and hardware buttons.
Figure F.1, illustrating Sample Input 1, shows a possible way to type CONTEST using 30 strokes on an example virtual keyboard. The red dots represent the virtual keys where the select button was pressed.
The input file contains several test cases, each of them as described below.
The first line of the input contains two integers r and c (1 ≤ r, c ≤ 50), giving the number of rows and columns of the virtual keyboard grid. The virtual keyboard is specified in the next r lines, each of which contains c characters. The possible values of these characters are uppercase letters, digits, a dash, and an asterisk (representing Enter). There is only one key corresponding to any given character. Each key is made up of one or more grid squares, which will always form a connected region. The last line of the input contains the text to be typed. This text is a non-empty string of at most 10 000 of the available characters other than the asterisk.
For each test case, display the minimal number of strokes necessary to type the whole text, including the Enter key at the end. It is guaranteed that the text can be typed.