#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i <= _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i >= _##i; --i)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef double LD;
const LD PI = 3.14159265358979323846;
const LD eps = 1e-10;
const LL N = 505;
LL n,m;
char g[N][N];
LL sum[N][N];
void solve() {
    cin>>n>>m;
    for(LL i = 1;i <= n;i++) cin>>g[i] + 1;
    for(LL i = 1;i <= n;i++) {
        for(LL j = 1;j <= m;j++) {
            sum[i][j] = sum[i][j - 1] + ((g[i][j] == '*') ? 1 : 0);
        }
    }
    LL ans = 0;
    for(LL i = 1;i <= n;i++) {
        for(LL j = 1;j <= m;j++) {
            if(g[i][j] == '*') {
                LL t;
                for(t = 1;t + i - 1 <= n;t++) {
                    if(j - t + 1 < 1 || j + t - 1 > m) break;
                    if(sum[t + i - 1][j + t - 1] - sum[t + i - 1][j - t] == 2 * t - 1) continue;
                    else break;
                }
                t--;
                ans += t;
            }
        }
    }
    cout<<ans<<endl;
}

int main() {
   // freopen("1.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin>>T;
    while(T--) {
        solve();
    }
    return 0;
}
