#include <vector>
#include <stack>
#include <iostream>
#include <iomanip>
#include <string>
#include <utility> 
#include <queue>
#include <cmath> 
#include <map> 
#include <unordered_map>
#include <array>
#include <algorithm>    // std::max
#define ll long long int
#define ld long double
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,x,y) for(int i = x; i < y; i++)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define maxN 100007
#define vi vector<int>
#define vs vector<string>
using namespace std; 


int solve() {
    ll N,n,m,w,s, ans = 0, p,q, R,C;
	cin >> n >> m;

	int a[n][m];
	rep(i,0,n){
		string s; cin >> s;
		rep(j,0,m){
			if(s[j] == '*'){
				ans++;
				a[i][j] = 1;
			} 
			else a[i][j] = 0;
		}
	}
	w = 1;

	while(1){
	int tree = 1 + w + w;
	if(tree > m) break;
	int d = tree-2;
	int ans1 = 0;
	rep(i,w,n){
		rep(j,w,m-w){
			if(a[i][j-1] >= d and a[i][j+1] >= d and a[i-1][j] >= d and a[i][j] >= d){
				a[i][j] = tree;
				ans++;
				// deb(i); deb(j);
			}
		}
	}
	// ans+=ans1;
	// deb(tree); deb(ans1);
	w++;
	}
	cout<< ans << "\n";
    return 0;
}

int main() {  
    fastio;
    int test_cases = 1;
    /////////////////////
    cin>>test_cases;/////
    /////////////////////
    while(test_cases--){
    solve();
    }
    return 0;
}