/*
Author : MishkatIT
Created : Tuesday 10-12-2024 16:27:09
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
const int inf = 1e9;
const ll linf = 1e18;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc;
cin >> tc;
while (tc--) {
int n, m;
cin >> n >> m;
int f = 0;
vector<vector<char>> v(n, vector<char>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> v[i][j];
f |= (v[i][j] == '+');
}
}
vector<vector<pair<int, int>>> ans(n, vector<pair<int, int>>(m));
for (int i = 0; i < n; i++) {
int cnt = 0;
for (int j = 0; j < m; j++) {
if (v[i][j] == '+') {
ans[i][j].first = cnt;
cnt++;
} else cnt = 0;
}
cnt = 0;
for (int j = m - 1; j >= 0; j--) {
if (v[i][j] == '+') {
ans[i][j].second = cnt;
cnt++;
} else cnt = 0;
}
}
vector<vector<pair<int, int>>> bns(n, vector<pair<int, int>>(m));
for (int j = 0; j < m; j++) {
int cnt = 0;
for (int i = 0; i < n; i++) {
if (v[i][j] == '+') {
bns[i][j].first = cnt;
cnt++;
} else cnt = 0;
}
cnt = 0;
for (int i = n - 1; i >= 0; i--) {
if (v[i][j] == '+') {
bns[i][j].second = cnt;
cnt++;
} else cnt = 0;
}
}
int mx = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
mx= max (mx, min({ans[i][j].first, ans[i][j].second, bns[i][j].first, bns[i][j].second}));
}
}
cout << mx * 4 + f << '\n';
}
return 0;
}