#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define all(v) v.begin(),v.end()
#define nl "\n"
#define FIO \
ios_base::sync_with_stdio(false);\
cin.tie(NULL);\
cout.tie(NULL);
const int N=1e5+9;
vector<vector<ll>>g; bool vis[N];
vector<ll>par, dis, col, topo, indegree;
void clr(ll n){
g.clear(); par.clear(); dis.clear();
g.resize(n+1); col.assign(n+1, 0);
indegree.assign(n+1, 0);
par.assign(n+1, -1); dis.assign(n+1, 0);
fill(vis, vis+n+1, false);
}
void solve(){
ll n, m; cin>>n>>m;
vector<vector<char>>g(n, vector<char>(m));
vector<vector<ll>>plusl(n, vector<ll>(m, 0));
vector<vector<ll>>plusr(n, vector<ll>(m, 0));
vector<vector<ll>>plusu(n, vector<ll>(m, 0));
vector<vector<ll>>plusd(n, vector<ll>(m, 0));
for(ll i=0;i<n;i++)
{
for(ll j=0;j<m;j++)
{
cin>>g[i][j];
}
}
for(ll i=0;i<n;i++)
{
ll k=0; if(g[i][0]=='+') plusl[i][0]++, k=1;
for(ll j=1;j<m;j++)
{
if(g[i][j]=='+'){
if(g[i][j]==g[i][j-1]) k++;
else k=1;
plusl[i][j]=k;
}else k=0;
}
k=0; if(g[i][m-1]=='+') plusr[i][m-1]++, k=1;
for(ll j=m-2; j>=0; j--){
if(g[i][j]=='+'){
if(g[i][j]==g[i][j+1]) k++;
else k=1;
plusr[i][j]=k;
}else k=0;
}
}
for(ll j=0;j<m;j++)
{
ll k=0; if(g[0][j]=='+') plusu[0][j]++, k=1;
for(ll i=1;i<n;i++)
{
if(g[i][j]=='+'){
if(g[i][j]==g[i-1][j]) k++;
else k=1;
plusu[i][j]=k;
}else k=0;
}
k=0; if(g[n-1][j]=='+') plusd[n-1][j]++, k=1;
for(ll i=n-2; i>=0; i--){
if(g[i][j]=='+'){
if(g[i][j]==g[i+1][j]) k++;
else k=1;
plusd[i][j]=k;
}else k=0;
}
}
ll ans=0;
for(ll i=0;i<n;i++)
{
for(ll j=0;j<m;j++)
{
if(g[i][j]=='+'){
ll k=min({plusu[i][j], plusd[i][j], plusl[i][j], plusr[i][j]});
k*=4; k-=3; ans=max(ans, k);
}
}
}
cout<<ans<<nl;
}
int32_t main()
{
FIO
ll t=1;
cin>>t;
for(ll i=1;i<=t;i++)
{
// cout<<"Case "<<i<<": ";
solve();
}
}