#include <bits/stdc++.h>
using namespace std;
const int N = 255;
char str[N][N];
int n, m, t, a[N][N];
int b[N][N], c[N][N];
inline int get(int x, int y) {
  if (x < 0 || y < 0) return 0;
  return a[x][y];
}
inline int gao(int x1, int y1, int x2, int y2) {
  if (x1 > x2 || x1 > n) return 0;
  if (y1 > y2 || y1 > m) return 0;
  return get(x2, y2) - get(x1 - 1, y2) - get(x2, y1 - 1) + get(x1 - 1, y1 - 1);
}
inline bool check(int i, int j, int d, int x) {
  return c[i + d][j - d] - c[i - 1][j + 1] == x &&
         c[i + 2 * d][j] - c[i + d - 1][j + d + 1] == x &&
         b[i + d][j + d] - b[i - 1][j - 1] == x &&
         b[i + 2 * d][j] - b[i + d - 1][j - d - 1] == x;
}
int main() {
  scanf("%d", &t);
  while (t--) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    memset(c, 0, sizeof(c));
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) {
      scanf("%s", str[i] + 1);
      for (int j = 1; j <= m; j++) {
        b[i][j] = c[i][j] = a[i][j] = str[i][j] - '0';
      }
    }
    for (int i = 1; i <= n + 2; i++) {
      for (int j = 1; j <= m + 2; j++) {
        a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
      }
    }
    for (int i = 1; i <= n + 2; i++) {
      for (int j = 1; j <= m + 2; j++) b[i][j] += b[i - 1][j - 1];
    }
    for (int i = 1; i <= n + 2; i++) {
      for (int j = m + 2; j >= 0; j--) c[i][j] += c[i - 1][j + 1];
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        for (int d = 1; d + i <= n && d + j <= m; d++) {
          if (d < 2 || (gao(i + 1, j + 1, i + 1, j + d - 1) == 0 &&
                        gao(i + d - 1, j + 1, i + d - 1, j + d - 1) == 0 &&
                        gao(i + 1, j + 1, i + d - 1, j + 1) == 0 &&
                        gao(i + 1, j + d - 1, i + d - 1, j + d - 1) == 0)) {
            if (gao(i, j, i, j + d) == d + 1 &&
                gao(i + d, j, i + d, j + d) == d + 1 &&
                gao(i, j, i + d, j) == d + 1 &&
                gao(i, j + d, i + d, j + d) == d + 1 &&
                gao(i - 1, j - 1, i - 1, j + d + 1) == 0 &&
                gao(i + d + 1, j - 1, i + d + 1, j + d + 1) == 0 &&
                gao(i - 1, j - 1, i + d + 1, j - 1) == 0 &&
                gao(i - 1, j + d + 1, i + d + 1, j + d + 1) == 0)
              ans++;
          }
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        for (int d = 1; i + 2 * d <= n && j + d <= m && j - d > 0; d++) {
          if (check(i, j, d, d + 1) &&
              b[i + 2 * d + 1][j] - b[i + d][j - d - 1] == 0 &&
              b[i + d][j + d + 1] - b[i - 1][j] == 0 &&
              c[i + d][j - d - 1] - c[i - 1][j] == 0 &&
              c[i + 2 * d + 1][j] - c[i + d][j + d + 1] == 0 &&
              c[i + 2 * d + 1][j + 1] - c[i + d + 1][j + 1 + d] == 0 &&
              c[i + d - 1][j - d - 1] - c[i - 1][j - 1] == 0 &&
              b[i + 2 * d + 1][j - 1] - b[i + d + 1][j - 1 - d] == 0 &&
              b[i + d - 1][j + d + 1] - b[i - 1][j + 1] == 0 &&
              gao(i - 1, j - 1, i - 1, j + 1) == 0 &&
              gao(i + 2 * d + 1, j - 1, i + 2 * d + 1, j + 1) == 0 &&
              gao(i + d - 1, j - d - 1, i + d + 1, j - d - 1) == 0 &&
              gao(i + d - 1, j + d + 1, i + d + 1, j + d + 1) == 0) {
            if (d == 1 && str[i + 1][j] == '0')
              ans++;
            else if (d > 1) {
              if (c[i + d][j - d + 1] - c[i][j + 1] == 0 &&
                  c[i + 2 * d - 1][j] - c[i + d - 1][j + d] == 0 &&
                  b[i + d][j + d - 1] - b[i][j - 1] == 0 &&
                  b[i + 2 * d - 1][j] - b[i + d - 1][j - d] == 0) {
                if (d == 2 && str[i + 2][j] == '0')
                  ans++;
                else if (d > 2 && check(i + 2, j, d - 2, 0))
                  ans++;
              }
            }
          }
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
