#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cout.tie(0), cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<string> ar(n);
    long long cnt = 0;
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    for (int i = 0; i < n; i++) {
      cin >> ar[i];
      for (int j = 0; j < m; j++) {
        dp[i][j] = (ar[i][j] == '*');
        cnt += (ar[i][j] == '*');
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 1; j < m; j++) {
        dp[i][j] += dp[i][j - 1];
      }
    }
    // 1st Sol. : from base to head but with binary search on answer - O(N^3 . Log(N)).
    // 2nd Sol. : let * in position [i, j] be the head of k-tree and try to go downward - O(N^3).
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (ar[i][j] == '*') {
          int rows = i + 1;
          int cols_left = j - 1;
          int cols_right = j + 1;
          int temp = 0;
          bool ok = true;
          while (rows < n && ok) {
            int cur = dp[rows][cols_right];
            if (cols_left - 1 >= 0) {
              cur -= dp[rows][cols_left - 1];
            }
            if (cur == cols_right - cols_left + 1) {
              temp++;
              rows++;
              cols_left--;
              cols_right++;
            } else {
              ok = false;
            }
          }
          cnt += temp;
        }
      }
    }
    cout << cnt << "\n";
  }
}
