#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n, m;
cin >> n >> m;
vector<vector<char>> a(n, vector<char>(m));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> a[i][j];
// Precompute directional lengths
vector<vector<int>> left(n, vector<int>(m, 0)), right(n, vector<int>(m, 0));
vector<vector<int>> up(n, vector<int>(m, 0)), down(n, vector<int>(m, 0));
// Fill 'left' and 'up'
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] == '+') {
left[i][j] = (j > 0 ? left[i][j - 1] : 0) + 1;
up[i][j] = (i > 0 ? up[i - 1][j] : 0) + 1;
}
}
}
// Fill 'right' and 'down'
for (int i = n - 1; i >= 0; i--) {
for (int j = m - 1; j >= 0; j--) {
if (a[i][j] == '+') {
right[i][j] = (j < m - 1 ? right[i][j + 1] : 0) + 1;
down[i][j] = (i < n - 1 ? down[i + 1][j] : 0) + 1;
}
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] == '+') {
int l = 1, r = 500, best = 1;
while (l <= r) {
int mid = (l + r) / 2;
if (left[i][j] >= mid && right[i][j] >= mid &&
up[i][j] >= mid && down[i][j] >= mid) {
best = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
ans = max(ans, 4 * (best - 1) + 1);
}
}
}
cout << ans << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc;
cin >> tc;
while (tc--) {
solve();
}
return 0;
}