#include <bits/stdc++.h>
using namespace std;
int main() {
int tc;
cin >> tc;
// assert(tc >= 1 && tc <= 10);
int total_cells = 0;
while(tc--) {
int n, m;
cin >> n >> m;
// assert(n >= 1 && n <= 2000);
// assert(m >= 1 && m <= 2000);
total_cells += n * m;
vector<string>grid(n);
for(int i = 0; i < n; i++) {
cin >> grid[i];
// cout << grid[i] << endl;
// cout << grid[i].size() << endl;
}
int best = 0;
vector<vector<int>> lc(n, vector<int>(m)), rc(n, vector<int>(m)), uc(n, vector<int>(m)), dc(n, vector<int>(m));
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if (grid[i][j] != '+') {
continue;
}
// cout << "here..." << endl;
lc[i][j] = (j > 0 ? lc[i][j - 1] : 0) + 1;
uc[i][j] = (i > 0 ? uc[i - 1][j] : 0) + 1;
}
}
for(int i = n - 1; i >= 0; i--) {
for(int j = m - 1; j >= 0; j--) {
if (grid[i][j] != '+') {
continue;
}
rc[i][j] = (j + 1 < m ? rc[i][j + 1] : 0) + 1;
dc[i][j] = (i + 1 < n ? lc[i + 1][j] : 0) + 1;
int side = min({lc[i][j], rc[i][j], uc[i][j], dc[i][j]});
// cout << "side: " << side << endl;
best = max(best, (side - 1) * 4 + 1);
}
}
cout << best << endl;
}
assert(total_cells >= 1 && total_cells <= 4000000);
}