#include<bits/stdc++.h>
#define ll          long long int
#define loop(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n)    for(int (i)=0;(i)<n;(i)++)
#define bp          1000000007
#define sz(a)       int((a).size())
#define pb          push_back
#define mp          make_pair
#define all(c)      (c).begin(),(c).end()
#define F           first
#define S           second
using namespace std;
typedef pair<ll,ll> ii;
char mat[501][501];
int nextFill[501][501];
int n,m;
int isSpruce(int i,int j){
	ll ans =0 ;
	for(int k=1;;k++){
		int i0 = i+k-1;
		int j0 = j-k+1;
		if(nextFill[i0][j0]>=2*k-1){
			ans++;
		}
		else{
			return ans;
		}
	}
	return ans;
}
void solve(){
	
	cin>>n>>m;
	memset(mat,0,sizeof(mat));
	memset(nextFill,0,sizeof(nextFill));
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>mat[i][j];
		}
	}
	for(int i=0;i<n;i++){
		nextFill[i][m-1] = (mat[i][m-1]=='*' ? 1:0);
		for(int j=m-2;j>=0;j--){
			if(mat[i][j]=='*')
				nextFill[i][j] = nextFill[i][j+1]+1;
		}
	}
	ll ans =0 ;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			// cout<<i<<","<<j<<","<<isSpruce(i,j)<<endl;
			ans += isSpruce(i,j);
		}
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		solve();	
	}
	
	return 0;
}