#include<bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define per(i,a,b) for(int i = (b) - 1;i >= (a); --i)
using namespace std;
string f[510];
int a[510][510];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--){
		int n,m;
		cin >> n >> m;
		rep(i,0,n)cin >> f[i];
		per(i,0,n)per(j,0,m){
			a[i][j] = (f[i][j] == '*');
			
			if(i < n - 1 && j > 0 && j < m - 1){
				a[i][j] += a[i][j]*(min(a[i+1][j],min(a[i+1][j-1],a[i+1][j+1])));
			}
		}
		int ans = 0;
		rep(i,0,n)rep(j,0,m)ans += a[i][j];
		cout << ans << '\n';
	}
	return 0;
}