#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define endl '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int a[505][505];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        mem(a,0);
        int n,m;
        cin>>n>>m;
        string s[n];
        ll ans=0;
        for(int i=0;i<n;i++)
        {
            cin>>s[i];
        }
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
                if(s[i][j]=='*')
                {
                    ans++;
                    a[i+1][j+1]=1;
                }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                a[i][j]=a[i][j-1]+a[i][j];
            }
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(s[i][j]=='*')
                {
                    ll ok=0;
                    for(int k=2;;k++)
                    {
                        if(i+k>n||j-k+1<0||j+k>m)
                            break;
                        int ok1=0;
                        if(a[i+k][j+k]-a[i+k][j-k+1]==2*k-1)
                            ok1=1;
                        //cout<<a[i+k][j-k+1]<<' '<<a[i+k][j+k]<<endl;
                        /*for(int g1=j-k+1;g1<=j+k-1;g1++)
                        {
                            if(s[i+k-1][g1]!='*')
                            {
                                ok1=0;
                                break;
                            }
                        }*/
                        if(ok1)
                        {
                            ok++;
                            //cout<<ok<<endl;
                        }
                        else
                        {
                            break;
                        }
                    }
                    ans+=ok;
                }
            }
        }
        cout<<ans<<endl;
    }
}
