#include<iostream>
#include<vector>
#include<unordered_map>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include<stack>

#define ll long long int
#define lim 9999999999
#define rep(i, j, s) for(i = s; i < j; i++)
#define rep_d(i, j, s) for(i = s; i>j; i--)
#define enter cout<<'\n'
#define NO cout<<"NO"
#define YES cout<<"YES"
#define pb(x) push_back(x)
using namespace std;
int i, j, k;
ll max(ll a, ll b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}

ll min(ll a, ll b){
    if(a<b){
        return a;
    }else{
        return b;
    }
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int n, m;
        cin>>n>>m;
        char mat[n][m];
        int dp[n][m];
        rep(i, n, 0){
            rep(j, m, 0){
                cin>>mat[i][j];
                if(mat[i][j] == '*'){
                    dp[i][j] = 1;
                }else{
                    dp[i][j] = 0;
                }
            }
        }
        int sum = 0;
        rep(i, n, 1){
            rep(j, m, 1){
                if(dp[i][j] ==1){
                    int x = min(dp[i-1][j], dp[i][j-1]);
                    int k;
                    for(k = 1; j+k < m && k <= x; k++){
                        if(dp[i][j+k]<1){
                            break;
                        }
                    }
                    dp[i][j] = k;
                }
            }
        }
        rep(i, n, 0){
            rep(j, m, 0){
                sum+=dp[i][j];
            }
        }
        cout<<sum;
        enter;
    }
    return 0;
}