#t140. 黑白方块
黑白方块
Black-and-White Blocks
Problem Description
Xiao Yang has a grid with rows and columns, where each cell is either white or black.
He wants to know whether there exists a sub-rectangle in the grid satisfying the following conditions:
- The sub-rectangle consists of rows and columns;
- The 1st and 4th rows of the sub-rectangle contain only white cells;
- For the 2nd and 3rd rows of the sub-rectangle, only the 1st and 4th cells are white, and all the other cells are black.
Write a program to help Xiao Yang decide.
Input Format
The first line contains a positive integer , the number of test cases.
The following are test cases. Each test case consists of lines.
The first line contains two positive integers , as described.
The following lines each contain a string of length consisting of 0 and 1, representing the colors of the cells in the -th row of the grid. If a character is 0, the corresponding cell is white; otherwise it is black.
Output Format
For each test case, if such a sub-rectangle exists, output Yes; otherwise output No.
Sample Input
3
1 4
0110
5 5
00000
01100
01100
00001
01100
5 5
00000
01100
01110
00001
01100
Sample Output
No
Yes
No
Sample Explanation
For the first test case, the grid is , so no sub-rectangle can be chosen; therefore no qualified sub-rectangle exists, and the output is No. The second test case has a qualified sub-rectangle, so the output is Yes. The third test case has no such sub-rectangle, so the output is No.
Constraints
For all test data, and are guaranteed.