Sir Monocarp Hamilton is planning to paint his wall. The wall can be represented as a grid, consisting of rows and columns. Initially, the wall is completely white.
Monocarp wants to paint a black picture on the wall. In particular, he wants cell (the -th cell in the -th row) to be colored black, if 'B', and to be left white, if 'W'. Additionally, he wants each column to have at least one black cell, so, for each , the following constraint is satisfied: , or both of them will be equal to 'B'.
In order for the picture to turn out smooth, Monocarp wants to place down a paint brush in some cell and move it along the path so that:
- for each , and share a common side; - all black cells appear in the path exactly once; - white cells don't appear in the path.
Determine if Monocarp can paint the wall.
## 输入格式
The first line contains a single integer ( ) — the number of testcases.
The first line of each testcase contains a single integer ( ) — the number of columns in the wall.
The -th of the next two lines contains a string , consisting of characters, where each character is either 'B' or 'W'. is 'B', if the cell should be colored black, and 'W', if the cell should be left white.
Additionally, for each , the following constraint is satisfied: , or both of them are equal to 'B'.
The sum of over all testcases doesn't exceed .
## 输出格式
For each testcase, print "YES" if Monocarp can paint a wall. Otherwise, print "NO".
In the first testcase, Monocarp can follow a path , , , with his brush. All black cells appear in the path exactly once, no white cells appear in the path.
In the second testcase, Monocarp can follow a path , .
In the third testcase:
- the path , , , , , , , doesn't suffice because a pair of cells and doesn't share a common side; - the path , , , , , , , , doesn't suffice because cell is visited twice; - the path , , , , , , doesn't suffice because a black cell doesn't appear in the path; - the path , , , , , , , , doesn't suffice because a white cell appears in the path.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)