#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main() {
    int t;
    for (cin >> t; t--;) {
        int n, m;
        cin >> n >> m;
        vector<string> b(n);
        for (auto& i : b)
            cin >> i;
        vector<vi> sp(n, vi(m, 0));
        for (int i = n-1; i >= 0; i--) {
            for (int j = 0; j < m; j++) {
                int aux = 0;
                while (j < m && b[i][j] == '*') {
                    aux++;
                    sp[i][j]++;
                    if (aux > 2 && i > 0) sp[i-1][j-1] += (b[i-1][j-1] == '*') * (min(sp[i][j], min(sp[i][j-1], sp[i][j-2])));
                    j++;
                }
            }
        }
        ll ans = 0;
        for (auto i : sp)
            for (auto j : i)
                ans += j;
        debug("end");
        cout << ans << endl;
    }
    return 0;
}
// 1 5 7
// ..*.*..
// .*****.
// *******
// .*****.
// ..*.*..