#include <bits/stdc++.h>
using namespace std;
template <class _T>
inline _T sqr(const _T &x) {
  return x * x;
}
template <class _T>
inline string tostr(const _T &a) {
  ostringstream os("");
  os << a;
  return os.str();
}
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1e-11;
const int dx[8] = {1, 1, 1, 0, -1, -1, -1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int n, m, qq;
char s[102400];
bool a[256][256];
bool u[256][256];
int q[65536][2];
void bfs(int x, int y, int &x1, int &y1, int &x2, int &y2, int &cnt) {
  int qb, qe;
  qb = qe = 0;
  q[qe][0] = x;
  q[qe][1] = y;
  qe++;
  u[x][y] = true;
  while (qb != qe) {
    x = q[qb][0];
    y = q[qb][1];
    cnt++;
    x1 = min(x1, x);
    y1 = min(y1, y);
    x2 = max(x2, x);
    y2 = max(y2, y);
    qb++;
    for (int l = 0; l < (int)(8); l++) {
      int xn = x + dx[l];
      int yn = y + dy[l];
      if (xn < 0 || xn >= n || yn < 0 || yn >= m || !a[xn][yn] || u[xn][yn])
        continue;
      u[xn][yn] = true;
      q[qe][0] = xn;
      q[qe][1] = yn;
      qe++;
    }
  }
}
int main() {
  cout << setiosflags(ios::fixed) << setprecision(10);
  scanf("%d", &qq);
  while (qq--) {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < (int)(n); i++) {
      scanf("%s", s);
      for (int j = 0; j < (int)(m); j++) {
        a[i][j] = s[j] == '1';
        u[i][j] = false;
      }
    }
    int ans = 0;
    for (int i = 0; i < (int)(n); i++) {
      for (int j = 0; j < (int)(m); j++) {
        if (!u[i][j] && a[i][j]) {
          int x1 = 1000, y1 = 1000, x2 = -1000, y2 = -1000, cnt = 0;
          bfs(i, j, x1, y1, x2, y2, cnt);
          if (x2 - x1 != y2 - y1) continue;
          int l = x2 - x1 + 1;
          if (cnt == l * 4 - 4) {
            bool ok = true;
            for (int x = (x1); x <= (int)(x2); x++) {
              ok = ok && a[x][y1];
              ok = ok && a[x][y2];
            }
            for (int y = (y1); y <= (int)(y2); y++) {
              ok = ok && a[x1][y];
              ok = ok && a[x2][y];
            }
            ans += ok;
          }
          if (l % 2 == 1 && cnt == l * 2 - 2) {
            bool ok = true;
            int xx = (x1 + x2) / 2;
            int yy = (y1 + y2) / 2;
            int zz = 0;
            for (int x = (x1); x <= (int)(xx); x++) {
              ok = ok && a[x][yy - zz];
              zz++;
            }
            zz = 0;
            for (int x = (x1); x <= (int)(xx); x++) {
              ok = ok && a[x][yy + zz];
              zz++;
            }
            zz = 0;
            for (int x = (x2); x >= (int)(xx); x--) {
              ok = ok && a[x][yy - zz];
              zz++;
            }
            zz = 0;
            for (int x = (x2); x >= (int)(xx); x--) {
              ok = ok && a[x][yy + zz];
              zz++;
            }
            ans += ok;
          }
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
