// Created by Nikolay Budin

#ifdef DEBUG
#  define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ff first
#define ss second
#define szof(x) ((int)x.size())
#ifndef LOCAL
#  define cerr __get_ce
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;
#ifdef LOCAL
	mt19937 tw(9450189);
#else
	mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
uniform_int_distribution<ll> ll_distr;
ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; }

void solve() {
	int n, m;
	cin >> n >> m;
	vector<vector<bool>> field(n, vector<bool>(m));
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		for (int j = 0; j < m; ++j) {
			field[i][j] = s[j] == '#';
		}
	}

	int ans = 0;
	for (int tr = 0; tr < 2; ++tr) {
		vector<pair<pii, pii>> vars;
		int best = 0;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				if (field[i][j]) {
					continue;
				}
				if (i == 0 || field[i - 1][j]) {
					int cnt = 0;
					while (i + cnt < n && !field[i + cnt][j]) {
						++cnt;
					}
					if (best < cnt) {
						best = cnt;
						vars.clear();
					}
					if (best == cnt) {
						vars.push_back({{i, j}, {i + cnt - 1, j}});
					}
				}

				if (j == 0 || field[i][j - 1]) {
					int cnt = 0;
					while (j + cnt < m && !field[i][j + cnt]) {
						++cnt;
					}
					if (best < cnt) {
						best = cnt;
						vars.clear();
					}
					if (best == cnt) {
						vars.push_back({{i, j}, {i, j + cnt - 1}});
					}
				}
			}
		}

		if (!szof(vars)) {
			break;
		}

		ans += best;
		auto p = vars[rnd(0, szof(vars) - 1)];
		for (int i = p.ff.ff; i <= p.ss.ff; ++i) {
			for (int j = p.ff.ss; j <= p.ss.ss; ++j) {
				field[i][j] = 1;
			}
		}
	}

	cout << ans << "\n";
}


int main() {
#ifdef LOCAL
	auto start_time = clock();
	cerr << setprecision(3) << fixed;
#endif
	cout << setprecision(15) << fixed;
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int test_count = 1;
	cin >> test_count;
	for (int test = 1; test <= test_count; ++test) {
		solve();
	}

#ifdef LOCAL
	auto end_time = clock();
	cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}