The input begins with the number of test cases it contains. After that, the test cases appear one after the other, each preceded by a line of white space. The input file will always end with an end-of-line (EOL).
Each test case contains the city grid, followed by an integer specifying the number of locations the Mayor can visit, followed by the locations in row-column order (zero based, the origin being the northwest corner of town). The city grid is described by two lines of text, each at least 2 and at most 10 characters long. The first line contains the directions of the East-West streets (E, W, or T for two-way). The second line contains the directions of the North-South streets (N, S, or T). Every location specified will be valid for the provided street grid.