#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long double ld;
typedef int ll;
typedef unsigned long long ull;
const ld PI = 4*atan((ld)1);
const ll mod = 1e9 + 7;
const ll nax = 1e5;

ll t, n, m;
ll pref[505][505];
char a[505][505];

ll cek(ll x, ll y, ll k, ll flag){
	if(!flag){
		if(x + k > n || y - k < 1 || y + k > m){
			return 0;
		}
		for(ll i = 0; i <= k; i++){
			ll ret = pref[x+i][y+i] - pref[x+i][y-i-1];
			if(ret != i * 2 + 1){
				return 0;
			}
		}
		return 1;
	}
	else{
		ll ret = pref[x+k][y+k] - pref[x+k][y-k-1];
		if(ret != k * 2 + 1){
			return 0;
		}
		return 1;
	}
}

int main(){ 
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    cin >> t;
    while(t--){
		memset(pref, 0, sizeof(pref));
		cin >> n >> m;
		for(ll i = 1; i <= n; i++){
			for(ll j = 1; j <= m; j++){
				cin >> a[i][j];
				//a[i][j] = '*';
				if(a[i][j] == '*'){
					pref[i][j]++;
				}
				pref[i][j] += pref[i][j-1];
			}
		}
		ll ans = 0;
		for(ll k = 0; k <= 250; k++){
			for(ll j = k + 1; j <= m - k; j++){
				ll flag = 0;
				for(ll i = 1; i <= n - k; i++){
					if(cek(i, j, k, flag)){
						ans++;
						flag = 1;
					}
					else{
						flag = 0;
					}
					//if(cek(i, j, k)) cout << i << " " << j << ' ' << k << '\n';
				}
			}
		}
		cout << ans << '\n';	
	}
}
