P22286 [HackerEarth] You are given a two-dimensional table (grid) A of N rows and M columns.
普及
题目描述

You are given a two-dimensional table (grid) A of N rows and M columns.
Every cell contains a lowercase letter, one of 'a' - 'z'.

Let's call two cells of A adjacent, if they share a common side.

Let's call a set S of cells a connected region if the following three conditions are satisfied:
S is connected, i.e. every pair of cells in S can be reached from each other by moving along a path of adjacent cells of S.
All the letters written in the cells of S are the same.
It's impossible to extend it, i.e. there are no more cells of A, that can be added to S so that the first two conditions still hold.

Let's say, that a connected region S is completely inside another connected region T, if there's a cycle path of adjacent cells of T, such that all the cells of S are inside the contour (shape), formed by the cycle path.

Let's call a table acceptable if there is no connected region completely inside some other connected region.
Your task is to determine whether the given table A is acceptable, and print $\text{YES}$ or $\text{NO}$ accordingly.

Input format
The first line contains one integer T denoting the number of test cases in the input.

The first line of each test case description contains two integers N and M denoting the number of rows and the number of columns in A respectively.

Each of the next N lines contains a string of M lowercase letters, each denoting one row of the table A.

Output format
For each test case, output the answer in a separate line.
The answer is $\text{YES}$ if the given table is acceptable, and $\text{NO}$ otherwise.

Constraints

1 ≤ T ≤ 18
1 ≤ $N \cdot M$ ≤ 10^6 (it's multiplication, not a comma)
N ≤ M.

SAMPLE INPUT
4
3 4
aaaa
abba
aaaa
3 4
aaac
abba
aaaa
4 5
xaaaa
aabca
abcca
aaaaa
6 6
aaaaaa
bbbbba
baaaba
babbba
baaaaa
bbbbbb

SAMPLE OUTPUT
NO
YES
NO
YES

Explanation

In the first test case of the sample input, the given table isn't acceptable because there is a connected region of b's completely inside a connected region of a's.

In the third test case, there are the following connected regions:
a connected region with one 'x'
a connected region with one 'b'
again, a connected region with one 'b'
a connected region with three letters 'c'
a connected region with 14 letters 'a'

Here, the given table isn't acceptable because all connected regions with b's and with c's are completely inside a connected region of a's.

Stack Limit for C++ is 8MB. You are allowed to increase it in your code, e.g. using setrlimit().

输入格式

见题面

输出格式

见题面

样例输入
18 2 2 aa aa 1 100 bkiawlfoiuwauqiumfxsvdytntjwvmumezdkmqunkbkbwlvpjwugcawuvnmrwdozjvtvksonqauqosurecvvudjedxyvmibtaclc 2 50 ysyqgcdwuucxneztccndaikosrjldliqahejqsaedhbhnrmmjc ivcvvsxlfdesvmthiavxeqqpgmatdhfigonbzslqwzelcrmspg 3 33 xroajdgzcdwqwnuxwiyouzvlnkhruigmq vmtovvtslimzxmvjokqjhlmrzkxbfhpvq baczynmseewtyqnfkkxyphjtseqdrqnad 4 25 qnqmvqllnojidkkttwazqjvme pgtsaakplfwfpzrwebnqrvvze cnjpbbahfvvpbvalnamdqchom dxcqhbziqsgsqmqoyoddbcuqk 10 10 cvdijoytdf nwvwoerwju dbxlsyaskc xgufummlfn rfbnvfltwb fkqfqkhqnk cgdssfjzgg jddvqazjcm attiyvfhbx yncaaghsbq 1 100 kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk 1 100 xhhhxxhhhxxxxxhxxhxxhxhxxhhxhxxhhhhxhhhhxhhhhxxxhxhhhxhhxxxxhhxhxhxhxxhxxhxhhhxhxhxxhhxxxhhxxxhxhxxx 3 33 iiibiibbibiibbbibbbbiiibiiibibiib bibbiibbibiibbbibiibibbbbbibbibib ibbiiibbbiiibiiiibbiiibbbiibiiibi 3 33 owwwwowwwwwowwwwwwwowwwwowoowowww wwwwwwwwwwwwwwwowoowwoowwwwwwwwww wwwowwwowwowwwwwwwwwwwwwwwwwwwowo 10 10 vvvvvvvgvv vvvvvvgvvg vvgvgvvvvv vvvvvvgvvv vvvvvvvgvg vvvvvvvvgv gvvvvvvvvg vvvvvvvvvv vvvvvvvvvv vvvvvvvvvv 10 10 jjljllljll jljljjljjl lllljllllj llljlljljj llllllllll ljjjjjlljl ljllljjljj lljjljjljl jjjjlljljl jllljjjjjl 10 10 abcdeabcde edcbaedcba abcdeabcde edcbaedcba abcdeabcde edcbaedcba abcdeabcde edcbaedcba abcdeabcde edcbaedcba 10 10 abcdeabcde dcbaedcbba eabcdeabcd dcbaedcbae eabccdeabc cbaedcbaed deabcdeabc baedcbaedd cdeabcdeab baedcbaedc 5 20 aaabbbbbccccccccdddd aaaaaaaaaaaeeeeedddd bbbbbbbbbbbbbbbbcccc eeeeeeeeeddddccccccc eeeaaaaaaaaaabbbbbbb 10 10 cbyhephcbm nlzzzzakgi jzzfzkzjmv reefzozzpq nsdwzwzjuq fdvxxreekc qtawxjtjdi iwdxxptwqn grokvttvua pxdrokknqr 10 10 jidemhvamb urzzzzbhsh rzzszwzjpm ruuvzhzzhu lnugzzzaqr smrdspysma ydkuftebyu ughmjjxxlj nbnatnmtrl fpuvvitgrx 10 10 puwlavdfsr abzzzzzicy xzzkzqzroi usqkzazzpx igpgzzzexx yxycsfkxnh lscrfyiqqm ehdluewtyg apuctnapiq voxhuidoqk
样例输出
YES YES YES YES YES YES YES YES YES NO NO NO YES YES YES YES YES NO