///Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define tp          tuple<int,int,int>
#define fastio      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb          push_back
#define F           first
#define S           second
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int N = 1e6 + 6;

ll fact[N];

ll dp[505][505],lft[505][505],rgt[505][505];

int main()
{
    fastio;
    read:
    int t;
    cin>>t;
    while(t--)
    {
        memset(dp,0,sizeof dp);
        memset(lft,0,sizeof lft);
        memset(rgt,0,sizeof rgt);
        int n,m;
        cin>>n>>m;
        string s;
        for(int i=1; i<=n; i++)
        {
            cin>>s;
            for(int j=0; j<m; j++)
            {
                if(s[j] == '*')
                    dp[i][j+1] = 1;
            }
        }
        for(int i=1;i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                if(dp[i][j])
                {
                    int c = 0;
                    for(int k=j-1; k>=1; k--)
                    {
                        if(dp[i][k])
                            c++;
                        else
                            break;
                    }
                    lft[i][j] = c;
                    c = 0;
                    for(int k=j+1; k<=m; k++)
                    {
                        if(dp[i][k])
                            c++;
                        else
                            break;
                    }
                    rgt[i][j] = c;
                }
            }
        }
//        for(int i=1; i<=n; i++)
//        {
//            for(int j=1; j<=m; j++)
//                cout<<lft[i][j]<<" ";
//            cout<<endl;
//        }
//        cout<<endl;
//        for(int i=1; i<=n; i++)
//        {
//            for(int j=1; j<=m; j++)
//                cout<<rgt[i][j]<<" ";
//            cout<<endl;
//        }
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                if(dp[i][j])
                {
                    for(int k=i+1,a=1; k<=n; k++,a++)
                    {
                        if(dp[k][j] == 1)
                        {
                            if(lft[k][j]>=a && rgt[k][j]>=a)
                                dp[i][j]++;
                            else
                                break;
                        }
                        else
                            break;
                    }
                }
            }
        }
        ll ans = 0;
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                ans += dp[i][j];
                //cout<<dp[i][j]<<" ";
            }
            //cout<<endl;
        }
        cout<<ans<<endl;
    }


   //goto read;
}
