#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define ld long double
#define f(a,b) for(ll i=a;i<b;i++)
#define f1(a,b) for(ll i=a;i<=b;i++)
#define fd(a,b) for(ll i=a;i>=b;i--)
#define fj(j,a,b) for(ll j=a;j<b;j++)
#define fat(m) for(auto it:m)
#define mi map<ll,ll>
#define mc map<char,ll>
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define vp vector<pair<ll,ll>>
#define pb push_back
#define all(v) v.begin(),v.end()
#define alld(v) v.begin(),v.end(),greater<ll>()
#define sz(v) v.size()
#define endl "\n"
#define ff first
#define ss second
const ll N=1e5+1;
 
void solve()
{
    ll n,m,k,p=0,q=0,s=0,c=0,i,j;
    //string a;
    cin>>n>>m;
    string a[n];
    f(0,n)
    {
        cin>>a[i];
    }
    ll l[n][m],r[n][m];
    memset(l,0,sizeof l);
    memset(r,0,sizeof r);
    f(0,n)
    {
        if(a[i][0]=='*')
            l[i][0]=1;
        if(a[i][m-1]=='*')
            r[i][m-1]=1;
    }
    f(0,n)
    {
        fj(j,1,m)
        {
            if(a[i][j]=='*')
            {
                l[i][j]=l[i][j-1]+1;
            }
        }
    }
    f(0,n)
    {
        for(j=m-2;j>=0;j--)
        {
            if(a[i][j]=='*')
            {
                r[i][j]=r[i][j+1]+1;
            }
        }
    }
    // f(0,n)
    // {
    //     fj(j,0,m)
    //         cout<<l[i][j]<<" ";
    //     cout<<endl;
    // }
    // cout<<endl;
    // f(0,n)
    // {
    //     fj(j,0,m)
    //         cout<<r[i][j]<<" ";
    //     cout<<endl;
    // }

    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(a[i][j]=='*')
            {
                s++;
                c=1;
                bool fg=0;
                for(k=i+1;k<n;k++)
                {
                    if(fg==1)
                        break;
                    if(a[k][j]=='*')
                    {
                        p=l[k][j]-1;
                        q=r[k][j]-1;
                        if(p>=c && q>=c)
                        {
                            s++;
                            c+=1;
                        }
                        else 
                        {
                            fg=1;
                            break;
                        }
                    }
                    else 
                        break;
                }
                
            }
        }
    }
    cout<<s<<endl;

    return;
}
 
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    cin>>t;
    while(t--)
        solve();
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
    #endif
    return 0;
}