#P1966B. Rectangle Filling
Rectangle Filling
No submission language available for this problem.
Description
There is an grid of white and black squares. In one operation, you can select any two squares of the same color, and color all squares in the subrectangle between them that color.
Formally, if you select positions and , both of which are currently the same color , set the color of all where and to .
This diagram shows a sequence of two possible operations on a grid:

Is it possible for all squares in the grid to be the same color, after performing any number of operations (possibly zero)?
The first line of the input contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers and () — the number of rows and columns in the grid, respectively.
Each of the next lines contains characters 'W' and 'B' — the initial colors of the squares of the grid.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, print "YES" if it is possible to make all squares in the grid the same color, and "NO" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
Input
The first line of the input contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers and () — the number of rows and columns in the grid, respectively.
Each of the next lines contains characters 'W' and 'B' — the initial colors of the squares of the grid.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, print "YES" if it is possible to make all squares in the grid the same color, and "NO" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
Note
In the first example, it is impossible to ever change the color of any square with an operation, so we output NO.
The second example is the case pictured above. As shown in that diagram, it is possible for all squares to be white after two operations, so we output YES.
In the third and fourth examples, all squares are already the same color, so we output YES.
In the fifth example we can do everything in two operations. First, select positions and and color all squares with and to white. Then, select positions and and color all squares with and to white. After these two operations all squares are white.