#include<bits/stdc++.h>
using namespace std;
int a[110][110];
bool check(int x,int y){
for(int i = 0;i <=3;i++){
if(a[x][y+i]) return 0;
if(a[x+3][y+i]) return 0;
}
for(int i = 0;i <= 3;i++){
if(a[x+1][y+i] == 0 && (i == 1 || i == 2)) return 0;
if(a[x+2][y+i] == 0 && (i == 1 || i == 2)) return 0;
if(a[x+1][y+i] == 1 && (i == 0 || i == 3)) return 0;
if(a[x+2][y+i] == 1 && (i == 0 || i == 3)) return 0;
}
return 1;
}
int main(){
int q;
cin >> q;
while(q--){
int n,m;
cin >> n >> m;
memset(a,0,sizeof(a));
for(int i = 1;i <= n;i++){
string s;
cin >> s;
for(int j = 1;j <= m;j++){
a[i][j] = s[j-1] - '0';
}
}
bool flag = false;
for(int x = 1;x <= n - 3;x++){
for(int y = 1;y <= m - 3;y++){
if(check(x,y)){
flag = true;
}
}
}
if(flag) cout << "Yes\n";
else cout << "No\n";
}
return 0;
}