#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#ifdef LOCAL
#include "debug.hpp"
#else
#define debug(...) 42
#endif
const ll N = 2009;
ll a[N][N], pref[N][N];
ll query(ll y1, ll y2, ll x1, ll x2) {
return pref[x2][y2] - pref[x1 - 1][y2] - pref[x2][y1 - 1] + pref[x1 - 1][y1 - 1];
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll T;
cin >> T;
while (T--) {
ll n, m;
cin >> n >> m;
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
char c;
cin >> c;
if (c == '+') {
a[i][j] = 1;
} else {
a[i][j] = 0;
}
}
}
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + a[i][j];
}
}
ll res = 0;
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
if (a[i][j] == 0)
continue;
ll l = 0, r = min(j - 1, m - j), ret = 0;
while (l <= r) {
ll m = l + r >> 1;
if (m == 0 || (query(j - m, j - 1, i, i) == m && query(j + 1, j + m, i, i) == m)) {
ret = m;
l = m + 1;
} else {
r = m - 1;
}
}
l = 0, r = min({ret, i - 1, n - i});
while (l <= r) {
ll m = l + r >> 1;
if (m == 0 || (query(j, j, i - m, i - 1) == m && query(j, j, i + 1, i + m) == m)) {
ret = m;
l = m + 1;
} else {
r = m - 1;
}
}
res = max(res, ret * 4 + 1);
}
}
cout << res << '\n';
}
}