欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1966B.Rectangle Filling
Rectangle Filling
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)?
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.
Samples
8
2 1
W
B
6 6
WWWWBW
WBWWWW
BBBWWW
BWWWBB
WWBWBB
BBBWBW
1 1
W
2 2
BB
BB
3 4
BWBW
WBWB
BWBW
4 2
BB
BB
WW
WW
4 4
WWBW
BBWB
WWBB
BBBB
1 5
WBBWB
NO
YES
YES
YES
YES
NO
YES
NO
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |