#include<bits/stdc++.h>
using namespace std;
#define ll int
#define db long double
#define vii vector<ll>
#define pll pair<ll, ll>
#define F first
#define S second
const ll N = (ll) 3e5 + 5;
const ll mod = (ll) 1e9 + 7;
const ll inf = (ll) 1e18;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
while(t--) {
ll a, b, c, i, j, k, m, n, o, x, y, z;
cin >> n >> m;
vector<vector<char>> s(n, vector<char>(m));
for(i = 0; i < n; i++) {
for(j = 0; j < m; j++) {
cin >> s[i][j];
}
}
vector<vii> piche(n, vii(m, 0)), upore(n, vii(m, 0));
ll ans = 0;
for(i = 0; i < n; i++) {
for(j = 0; j < m; j++) {
if(s[i][j] == '+') {
if(j == 0)
piche[i][j] = 1;
else
piche[i][j] = piche[i][j - 1] + 1;
if(i == 0)
upore[i][j] = 1;
else
upore[i][j] = upore[i - 1][j] + 1;
ll mn = min(piche[i][j], upore[i][j]);
ll jj = j;
while(jj < m && s[i][jj] == '+') {
jj++;
}
mn = min(mn, jj - j);
ll ii = i;
while(ii < n && s[ii][j] == '+') {
ii++;
}
mn = min(mn, ii - i);
ans = max(ans, mn);
}
}
}
cout << (ans == 0 ? 0 : (ans << 2) - 3) << "\n";
}
}