#include
#include
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t–)
{
int n,m;
cin>>n>>m;
string arr[10000000];
int count=0;
vector<pair<int,int>>v;
for(int i=0;i<n;i++)
{
cin>>arr[i];
for(int j=0;j<m;j++)
{
if(arr[i][j]=='1')
{
v.push_back({i,j});
count++;
}
}
}
int a = v[0].first;
int b = v[v.size()-1].first;
int c = v[0].second;
int d = v[v.size()-1].second;
int k=(abs(b-a)+1)*(abs(c-d)+1);
int sum=0;
for(int i=0;i<count;i++)
{
if((min(a,b)<=v[i].first && max(a,b)>=v[i].first && min(c,d)<=v[i].second && max(c,d)>=v[i].second))
{
sum++;
}
}
if(sum==count)
{
cout<<"YES"<<"\n";
}
else
{
cout<<"NO"<<"\n";
}
}
}
whats wrong in thi solution…i am counting total number of cells between left most and right most…and equating it to total number of 1s…nd making sure all 1s lie between top left most and bottom right most