Reservior

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
You are given a structure of a water reservoir. The reservoir is a 2 dimensional structure of height N and width M. It can be thought of divided into M vertical sections, each of equal width. The reservoir height is of N blocks. Each block of the reservoir can contain either water, brick or air. We will denote the water by character 'W', brick by 'B' and air by 'A'.
You are given representation of reservoir at a fixed instant. Can you tell whether the current state of reservoir is stable, i.e. it will remain on the same state forever or not?
For example, let the reservoir be
WW BBThis is not stable, as the water in the block (1, 1) can overflow to the left, similarly water in block (1, 2) can overflow to the right too.
BWB BBBThis is stable, as the water at block (1, 2) is entrapped between bricks from all sides.
AWA BBBThis is not stable, as the water at block (1, 2) might overflow to the left or the right.
BAA ABBThis is not stable, as there is a brick at block (1, 1) and air at (2, 1). The brick will go down and air will come up, so its not stable too.
BWAAB BWBWB BBBBBThis is not stable too, as there is water at block (1, 2) and air at (1, 3), and (1, 4). The water will move towards those blocks.
BBB BAB BBBSo brick at (1, 2) is loose and without support, and hence will fill the space beneath it, which is right now filled with air. That is, the brick will go down and replace the air
BBB BWB BBBThis is also unstable due to the same reason as the above.
Now, you are given description of reservoir. Can you tell whether the current state of reservoir is stable or not?
Input
The first line of input contains an integer T denoting number of test cases. Description of T test cases follows.
The first line of each test case, contains two integers N and M denoting the height and width of reservoir, respectively.
Each of the next N lines a string of length M. The jth character in the ith of the line denotes content at block (i, j). The characters can be 'B' denoting brick, 'A' denoting air, 'W' denoting water.
Output
For each test case, output a line containing "yes" or "no" (without quotes) corresponding to the situation whether the reservoir is stable or not?
Constraints
 1 ≤ T ≤ 50
 1 ≤ N, M ≤ 1000
Subtask #1: (15 points)
 There is no water in the reservoir.
Subtask #2: (25 points)
 1 ≤ N, M ≤ 100
 original constraints
Example
Input: 7 2 2 WW BB 2 3 BWB BBB 2 3 AWA BBB 2 3 BAA ABB 3 5 BWAAB BWBWB BBBBB 3 3 BBB BAB BBB BBB BWB BBB Output: no yes no no no no no
Explanation
All the examples are explained in the problem statement itself.
Author:  admin2 
Editorial  https://discuss.codechef.com/problems/RESERVOI 
Tags  adhoc, admin2, jan17, simple 
Date Added:  3012017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 