John is on a mission to retrieve some important documents from a one-story building. He has managed to obtain a detailed floor plan of the building, indicating the locations of all the documents. There are doors in the building that require a key to be opened. John has some keys in his possession, and there are some keys in the building itself.
Can you help him figure out how many documents he can retrieve?
The first line contains one positive number: the number of test cases, at most . After that, for each test case:
One line with two space-separated integers and (2 \leq h, w \leq 100): the height and width of the map.
lines, each with characters, describing the building:
. is an empty space.
* is an impenetrable wall.
$ is a document that John needs to retrieve.
An uppercase letter is a door.
A lowercase letter is a key that opens all doors corresponding to its uppercase equivalent.
One line with a string consisting of distinct lowercase letters: the keys that John has in his possession. If he has no keys, the line contains 0 instead.
John can freely move around the outside of the building. For any given door, the number of available keys that open it can be zero, one, or more than one. For any given key, the number of doors that it opens can be zero, one, or more than one. Keys can be reused.
For each test case, print one line with an integer: the total number of documents that John can retrieve.
Example 1