Palindromic grid

4

7 votes
Basic Programming, Basics of Implementation, Easy, Implementation, String Manipulation
Problem

You are given a 2-d grid of N rows and columns containing lower case alphabets only. You need to check whether it is possible to rearrange the complete grid so that each row and column becomes palindromic.

Input : 

  • The first line of input contains T, the number of test cases. 
  • The first line of each test case contains two space-separated integers N and M, denoting the number of rows and columns.
  • Each of the following lines contains a string of length M.

Output :

  • Output YES if it is possible to rearrange the grid to make all the rows and columns palindromic. else output NO.

Constraints :

  • 1T10
  • 1N,M103

 

Sample Input
2
2 2
aa
aa
2 3
aba
aca
Sample Output
YES
NO
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The given arrangement already have all the rows and columns palindromic.

Editor Image

?