#include<bits/stdc++.h>
 
#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
 
#define ll long long
#define pb push_back
 
#define srt(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
 
#define inf 0x3f3f3f3f3f3f3f3fLL
#define mxn 1000005
#define mod 1000000007
#define pi acos(-1)
 
#define yes printf("YES\n")
#define no printf("NO\n")
 
#define r0 return 0
 
using namespace std;
 
string mirror="AHIMOTUVWXY";
 
int main()
{
    ll n,m,i,j,k,x,y,z,t;
 
    cin>>t;
 
    while(t--)
    {
        cin>>n>>m;
 
        ll cnt=0;
 
        char s[n+5][m+5];
 
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                cin>>s[i][j];
            }
        }
 
        ll a[n+5][m+5];
 
        memset(a,0,sizeof(a));
 
        ll cur=0;
 
        for(i=1;i<=n;i++)
        {
            cur=0;
 
            for(j=1;j<=m;j++)
            {
                if(s[i][j]=='*')cnt++,cur++;
                else cur=0;
 
                a[i][j]=cur;
            }
        }
 
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(s[i][j]=='.')continue;
 
                k=i+1;
 
                x=j-1;
                y=j+1;
 
                if(k>n || x<=0 || y>m)continue;
 
                while(1){
 
                    ll tmp=a[k][y]-a[k][x-1];
 
                    if(tmp==y-x+1)cnt++;
                    else break;
 
                    k++;
                    x--;
                    y++;
 
                       if(k>n || x<=0 || y>m)break;
                }
            }
        }
 
 
 
        cout<<cnt<<endl;
    }
}