#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define pi 2*acos(0.0)
void solve()
{
int n,m;
cin>>n>>m;
char ch[n+1][m+1];
bool have=false;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cin>>ch[i][j];
if(ch[i][j]=='+'){
have=true;
}
}
}
if(!have){
cout<<0<<endl;
return;
}
vector<pair<int,int>> ps;
for(int i=2; i<n; i++){
for(int j=2; j<m; j++){
if(ch[i][j]=='+'){
if(ch[i][j+1]=='+' && ch[i][j-1]=='+' && ch[i-1][j]=='+' && ch[i+1][j]=='+'){
ps.push_back({i,j});
}
}
}
}
// for(auto &it: ps){
// cout<<it.first<<" "<<it.second<<endl;
// }
if(ps.size()==0){
cout<<1<<endl;
return;
}
int maxi=-1,c1=0,c2=0,c3=0,c4=0;
int mx = 2*min(n,m)-1;
for(auto it: ps){
int f=it.first,s=it.second;
//cout<<f<<" "<<s<<endl;
for(int i=s-1; i>=1; i--){
if(ch[f][i]=='+'){
c1++;
}
else break;
}
for(int i=s+1; i<=m; i++){
if(ch[f][i]=='+'){
c2++;
}
else break;
}
for(int i=f-1; i>=1; i--){
if(ch[i][s]=='+'){
c3++;
}
else break;
}
for(int i=f+1; i<=n; i++){
if(ch[i][s]=='+'){
c4++;
}
else break;
}
//cout<<c1<<" "<<c2<<" "<<c3<<" "<<c4<<endl;
int min1=min(c1,c2);
int min2=min(c3,c4);
int mini=min(min1,min2);
//cout<<"mini "<<mini<<endl;
maxi=max(maxi,((4*mini)+1));
if(maxi==mx){
cout<<maxi<<endl;
return;
}
c1=0,c2=0,c3=0,c4=0;
}
cout<<maxi<<endl;
}
int32_t main ()
{
ios::sync_with_stdio(false); cin.tie(nullptr);
int t = 1;
cin >> t;
while(t--) {
solve();
}
return 0;
}