/*
	++ INTERNATIONAL GRANDMASTER IS NEAR TO YOU THAN YOU THINK ABOUT IT ++
	Mr.SaMaDi :)
*/
#include<bits/stdc++.h>
using namespace std ; 
typedef long long ll ;

constexpr ll MAXN = 5e2 + 10 ;
constexpr ll MOD = 1e9 + 7 ;

#define debug(x)               cerr << #x << " : " << x << endl
#define here                            cout << "here\n" 

int t ,n ,m ,part[MAXN][MAXN]; 
ll ans ;
string s[MAXN] ; 

bool Check(int i ,int l ,int r ,int len){
	return (part[i][r] >= len); 
}

int main (){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0) ;  
	cin >> t ; 
	while (t--){
		ans = 0 ;
		cin >> n >> m ; 
		for (int i = 0; i < n; i++){
			cin >> s[i] ; 
		}
		for (int i = 0; i < n; i++){
			for (int j = 0; j < m; j++){
				part[i][j] = (s[i][j] == '*') ; 
				if (part[i][j] && j){
					part[i][j] += part[i][j - 1] ; 
				}
			} 
		}
		for (int i = 0; i < n; i++){
			for (int j = 0; j < m; j++){
				for (int len = 1 ;len + i - 1 < n && j - len + 1 >= 0 && j + len - 1 < m; len++){
					if (Check(i + len - 1 ,j - len + 1 ,j + len - 1 ,len * 2 - 1)){  
						ans++ ;  
					}
					else {
						break ; 
					}
				}
			}
		}
		cout << ans << "\n" ; 
	} 
	return 0 ; 
}
