#include <iostream>
using namespace std;
int t;
int n, m;
string s[105];
bool pd(int i, int j)
{
for (int x = i; x < i + 4; x++)
for (int y = j; y < j + 4; y++)
if (x == i || x == i + 3 || y == j || y == j + 3)
{
if (s[x][y] == '1')
return false;
}
else
{
if (s[x][y] == '0')
return false;
}
return true;
}
int main()
{
cin >> t;
while (t--)
{
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> s[i];
bool f = false;
for (int i = 0; i < n - 4; i++)
{
if (f)
break;
for (int j = 0; j < m - 4; j++)
{
if (pd(i, j))
{
f = true;
break;
}
}
}
if (f)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}