#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
int n, m; cin >> n >> m;
vector<vector<char>> s(n, vector<char> (m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> s[i][j];
}
}
vector<vector<int>> Max(n, vector<int> (m, n));
for (int i = 0; i < n; i++) {
int cur = 0;
for (int j = 0; j < m; j++) {
cur += (s[i][j] == '+' ? 1 : -cur);
Max[i][j] = min(Max[i][j], cur);
}
cur = 0;
for (int j = m -1; j >= 0; j--) {
cur += (s[i][j] == '+' ? 1 : -cur);
Max[i][j] = min(Max[i][j], cur);
}
}
for (int j = 0; j < m; j++) {
int cur = 0;
for (int i = 0; i < n; i++) {
cur += (s[i][j] == '+' ? 1 : -cur);
Max[i][j] = min(Max[i][j], cur);
}
cur = 0;
for (int i = n -1; i >= 0; i--) {
cur += (s[i][j] == '+' ? 1 : -cur);
Max[i][j] = min(Max[i][j], cur);
}
}
int ans = 0;
for (auto& r : Max) {
for (auto& c : r) ans = max(ans, c);
}
if (ans) {
cout << 1 + 4 * (ans - 1) << '\n';
} else {
cout << 0 << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1;
cin >> tt;
for(int t = 1; t <= tt; t++) {
solve();
}
}