#include<bits/stdc++.h>
using namespace std;
#define ll long long
#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];
}
// cerr << s[i] << "\n";
}
vector<vii> shoja, ulta, dan, bam;
shoja.assign(n, vii(m, 0));
ulta = dan = bam = shoja;
// cerr << dan.size() << "\n";
for(i = 0; i < n; i++) {
for(j = 0; j < m; j++) {
// cout << s[i][j] << "\n";
if(s[i][j] == 43) {
// cerr << i << " " << j << "\n";
if(i == 0)
shoja[i][j] = 1;
else
shoja[i][j] = shoja[i - 1][j] + 1;
if(j == 0)
bam[i][j] = 1;
else
bam[i][j] = bam[i][j - 1] + 1;
} else {
shoja[i][j] = 0;
bam[i][j] = 0;
}
}
}
// cerr << shoja[2][1] << "\n";
for(i = n - 1; i >= 0; i--) {
for(j = m - 1; j >= 0; j--) {
if(s[i][j] == 43) {
if(i == n - 1)
ulta[i][j] = 1;
else
ulta[i][j] = ulta[i + 1][j] + 1;
if(j == m - 1)
dan[i][j] = 1;
else
dan[i][j] = dan[i][j + 1] + 1;
} else {
ulta[i][j] = 0;
dan[i][j] = 0;
}
}
}
ll ans = 0;
for(i = 0; i < n; i++) {
for(j = 0; j < m; j++) {
ans = max(ans, 4 * min({shoja[i][j], ulta[i][j], dan[i][j], bam[i][j]}) - 3);
}
}
cout << ans << "\n";
}
}