#include <bits/stdc++.h>

using namespace std;
using pii = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;

const int N = 5e2 + 2;

#define MOD 1000000007

char grid[N][N];
int pre[N][N];

ll query(int l1, int r1, int l2, int r2) {
    ll res = pre[l2][r2];

    if(l1 > 0)
        res -= pre[l1 - 1][r2];
    if(r1 > 0)
        res -= pre[l2][r1 - 1];
    if(l1 > 0 && r1 > 0)
        res += pre[l1 - 1][r1 - 1];

    return res;
}

int main() {
    ios_base::sync_with_stdio(false);

    int T; cin >> T;

    while(T--) {
        int n, m; cin >> n >> m;

        for(int i = 0; i < n; i++)
            cin >> grid[i];

        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                pre[i][j] = grid[i][j] == '*';

                if(i > 0)
                    pre[i][j] += pre[i - 1][j];
                if(j > 0)
                    pre[i][j] += pre[i][j - 1];
                if(i > 0 && j > 0)
                    pre[i][j] -= pre[i - 1][j - 1];
            }
        }

        ll res = 0;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if(grid[i][j] != '*')
                    continue;

                int cnt = 0;
                for(int k = i; k < n; k++) {
                    int num = 2 * (k - i) + 1;

                    int f = j - num / 2;
                    int l = j + num / 2;

                    if(f < 0 || l >= m)
                        break;

                    if(query(k, f, k, l) == num)
                        cnt++;
                    else
                        break;
                }

                res += cnt;
            }
        }

        cout << res << "\n";
    }

    return 0;
}



