#include <bits/stdc++.h>

#define ed end()
#define bg begin()
#define mp make_pair
#define pb push_back
#define all(x) x.bg,x.ed
#define newline puts("")
#define si(x) ((int)x.size())
#define rep(i,n) for(int i=1;i<=n;++i)
#define rrep(i,n) for(int i=0;i<n;++i)
#define srep(i,s,t) for(int i=s;i<=t;++i)
#define drep(i,s,t) for(int i=t;i>=s;--i)

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int Maxn = 1e5+10;
const int Inf = 0x7f7f7f7f;
const ll Inf_ll = 1ll*Inf*Inf;
const int Mod = 1e9+7;
const double eps = 1e-7;

int n, m;
char s[550][550];
int a[550][550];

void solve(){
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)  scanf("%s",s[i]+1);
    int ans = 0;
    for(int i=n;i>=1;i--)  for(int j=1;j<=m;j++)
    {
        if( s[i][j] == '*' )
            a[i][j] = min(a[i+1][j-1], min(a[i+1][j], a[i+1][j+1])) + 1;
        ans += a[i][j];
    }
    printf("%d\n", ans);
    for(int i=1;i<=n;i++)  for(int j=1;j<=m;j++)  a[i][j] = 0;
}

int main(){
    int T;
    scanf("%d",&T);
    for(int _=1;_<=T;_++)
    {
        solve();
    }
    return 0;
}