//--@farmanalam123--//
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
    	int n,m;
    	cin>>n>>m;
    	char a[n][m];
    	int b[n][m];
    	for(int i=0;i<n;i++)
    	{
    		for(int j=0;j<m;j++)
    		{
    			cin>>a[i][j];
    			b[i][j]=0;
    		}
    	}
    	ll c=0;
    	for(int i=n-1;i>=0;i--)
    	{
    		for(int j=0;j<m;j++)
    		{
    			if(a[i][j]=='*')
    				b[i][j]=1;
    			if(i+1<n && j<m-1 && j-1>=0 && a[i][j]=='*')
    			{
    				if(b[i+1][j-1]==b[i+1][j] && b[i+1][j]==b[i+1][j+1])
    					b[i][j]=b[i+1][j]+1;
    				else if(b[i+1][j-1]>=1 && b[i+1][j]>=1 && b[i+1][j+1]>=1)
    					b[i][j]=min(b[i+1][j-1],min(b[i+1][j],b[i+1][j+1]))+1;
    				// cout<<i<<" "<<j<<endl;
    			}
    			c+=b[i][j];
    		}
    	}
    	cout<<c<<endl;
    }
    return 0;
}