#include <bits/stdc++.h>
inline int cmp(double x, double y = 0, double tol = 1e-9) {
  return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
int n, m;
int map[300][300];
int main() {
  int t;
  char c;
  std::cin >> t;
  while (t--) {
    memset(map, 0, sizeof(map));
    int answer = 0;
    std::cin >> n >> m;
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) {
        std::cin >> c;
        map[i][j] = c - '0';
      }
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) {
        int ok = 1, side = 0;
        if (!map[i][j] || map[i - 1][j - 1])
        next:
          continue;
        while (map[i + side][j] && map[i][j + side]) {
          if (map[i + side][j - 1] || map[i - 1][j + side]) goto next;
          ++side;
        }
        if (side < 2) goto next;
        for (int k = 0; k < side; ++k)
          if (!map[i + side - 1][j + k] || !map[i + k][j + side - 1]) goto next;
        for (int k = -1; k <= side; ++k)
          if (map[i + side][j + k] || map[i + k][j + side]) goto next;
        for (int k = 1; k < side - 1; ++k)
          if (map[i + 1][j + k] || map[i + k][j + 1] ||
              map[i + side - 2][j + k] || map[i + k][j + side - 2])
            goto next;
        ++answer;
      }
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) {
        int ok = 1, side = 0;
        if (!map[i][j] || map[i - 1][j])
        next2:
          continue;
        while (map[i + side][j + side] && map[i + side][j - side]) {
          if (map[i + side - 1][j - side] || map[i + side + 1][j - side] ||
              map[i + side - 1][j + side] || map[i + side + 1][j + side] ||
              map[i + side][j - side - 1] || map[i + side][j - side + 1] ||
              map[i + side][j + side - 1] || map[i + side][j + side + 1] ||
              map[i + side - 1][j - side - 1] ||
              map[i + side - 1][j + side + 1])
            goto next2;
          ++side;
        }
        if (side < 2) goto next2;
        for (int di = side - 1, dj = side - 1; di <= 2 * (side - 1); ++di, --dj)
          if (!map[i + di][j - dj] || !map[i + di][j + dj]) goto next2;
        for (int di = side - 1, dj = side - 1; di <= 2 * (side - 1); ++di, --dj)
          if (map[i + di][j - dj + 1] || map[i + di + 1][j - dj] ||
              map[i + di + 1][j - dj - 1] || map[i + di][j + dj - 1] ||
              map[i + di + 1][j + dj] || map[i + di + 1][j + dj + 1])
            goto next2;
        for (int k = 1; k < side - 1; ++k)
          if (map[i + k + 1][j - k + 1] || map[i + k + 1][j + k - 1] ||
              map[i + side + k - 2][j - side + k + 2] ||
              map[i + side + k - 2][j + side - k - 2])
            goto next2;
        ++answer;
      }
    std::cout << answer << std::endl;
  }
  return 0;
}
