#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ll long long
#define int long long
#define pii pair<int, int>
void solve(){
int n, m; cin >> n >> m;
int mx = max(n,m);
int a[mx+2][mx+2];
int prea[mx+2][mx+2], prera[mx+2][mx+2];
int sufa[mx+2][mx+2], sufra[mx+2][mx+2];
memset(a, 0, sizeof a);
memset(prea, 0, sizeof prea);
memset(sufa, 0, sizeof sufa);
memset(prera, 0, sizeof prera);
memset(sufra, 0, sizeof sufra);
for(int i=1;i<=n;++i) {
for(int j=1;j<=m;++j){
char c; cin >> c;
a[i][j] = (c == '+');
}
}
for(int i=1;i<=mx;++i) {
for(int j=1;j<=mx;++j) {
prea[i][j] = a[i][j];
if(a[i][j])
prea[i][j] = prea[i][j-1] + a[i][j];
}
for(int j=mx;j>=1;--j) {
sufa[i][j] = a[i][j];
if(a[i][j])
sufa[i][j] = sufa[i][j+1] + a[i][j];
}
}
for(int i=1;i<=mx;++i) {
for(int j=1;j<=mx;++j) {
prera[i][j] = a[i][j];
if(a[i][j])
prera[i][j] = prera[i-1][j] + a[i][j];
}
}
for(int i=mx;i>=1;--i) {
for(int j=mx;j>=1;--j) {
sufra[i][j] = a[i][j];
if(a[i][j])
sufra[i][j] = sufra[i+1][j] + a[i][j];
}
}
// for(int i=1;i<=mx;++i) {
// for(int j=1;j<=mx;++j){
// cout << sufra[i][j] << " \n"[j==mx];
// }
// }
int ans = 0;
for(int i=1;i<=mx;++i){
for(int j=1;j<=mx;++j){
if(a[i][j] == 0) continue;
int left = prea[i][j];
int right = prera[i][j];
int top = sufa[i][j];
int down = sufra[i][j];
int now = min({left , right , top , down})*4 - 3 ;
ans = max(ans, now);
// cerr << i << " " << j << " " << now << endl;
}
}
cout << ans << nl;
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1, tc = 0;
cin >> t ;
while(t--){
// cout << "Case " << ++tc << ": ";
solve();
}
return 0;
}