#P1766C. Hamiltonian Wall
Hamiltonian Wall
Description
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".
Input
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 .
Output
For each testcase, print "YES" if Monocarp can paint a wall. Otherwise, print "NO".
Note
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.