#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <deque>
#include <climits>
#include <cmath>
#include <numeric>
#include <string>
#include <bitset>
#include <assert.h>
#include <iomanip>
using namespace std;
template <typename T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/
/*
#include <bits/stdc++.h>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define getrand(l, r) uniform_int_distribution<int>(l, r)(rng)
*/
const long long infl = 1e18 + 1;
const int inf = 1e9 + 1;
const int mod1 = 1e9 + 7;
const int mod2 = 998244353;
const long double eps = 1e-7;
const int mod = mod1;
int add(int a, int b) { return (a + b) % mod; }
int sub(int a, int b) { return (a - b + mod) % mod; }
int mul(int a, int b) { return (int)((long long)a * b % mod); }
int pwr(int a, int b = mod - 2)
{
int res = 1;
for(; b > 0; b >>= 1, a = mul(a, a))
if(b & 1)
res = mul(res, a);
return res;
}
template <typename T>
bool chmax(T &a, T b)
{
if(b > a)
{
a = b;
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, T b)
{
if(b < a)
{
a = b;
return true;
}
return false;
}
void solve()
{
int n, m;
cin >> n >> m;
vector a(n, vector<char>());
for(int i = 0; i < n; i++)
{
int cnt = 0;
while(cnt < m)
{
char c;
cin >> c;
if(c == ' ')
continue;
a[i].push_back(c);
cnt++;
}
}
vector pref(n + 1, vector<int>(m + 1, 0));
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + (a[i - 1][j - 1] == '+');
auto query = [&](int i1, int j1, int i2, int j2) -> int
{
i1++, j1++, i2++, j2++;
return pref[i2][j2] - pref[i2][j1 - 1] - pref[i1 - 1][j2] + pref[i1 - 1][j1 - 1];
};
int mx = 0;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
{
int l = 0, r = min({i, j, n - i - 1, m - j - 1});
while(l <= r)
{
int md = (l + r) / 2;
bool can = true;
can &= query(i - md, j, i, j) == md + 1;
can &= query(i, j - md, i, j) == md + 1;
can &= query(i, j, i + md, j) == md + 1;
can &= query(i, j, i, j + md) == md + 1;
if(can)
{
l = md + 1;
chmax(mx, md * 4 + 1);
}
else
r = md - 1;
}
}
cout << mx;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while (t--)
{
solve();
cout << (t ? "\n" : "");
}
}