#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
char s[255][255];
int u[255][255];
int now;
int n, m, cc;
void dfs(int x, int y) {
  if (u[x][y] == now) return;
  u[x][y] = now;
  cc++;
  for (int dx(-1); dx < (2); dx++)
    for (int dy(-1); dy < (2); dy++) {
      int nx = x + dx;
      int ny = y + dy;
      if (nx >= 0 && nx < n && ny >= 0 && ny < m && s[nx][ny] == '1')
        dfs(nx, ny);
    }
}
int main() {
  int TC;
  cin >> TC;
  for (int tc(0); tc < (TC); tc++) {
    cin >> n >> m;
    gets(s[0]);
    for (int i(0); i < (n); i++) gets(s[i]);
    int res = 0;
    now++;
    for (int i(0); i < (n); i++)
      for (int j(0); j < (m); j++)
        if (u[i][j] != now && s[i][j] == '1') {
          bool good = false;
          int len = 0;
          while (j + len < m && s[i][j + len] == '1') len++;
          if (len > 1 && i + len <= n) {
            good = true;
            for (int z(0); z < (len); z++)
              if (s[i][j + z] != '1') good = false;
            for (int z(0); z < (len); z++)
              if (s[i + z][j] != '1') good = false;
            for (int z(0); z < (len); z++)
              if (s[i + z][j + len - 1] != '1') good = false;
            for (int z(0); z < (len); z++)
              if (s[i + len - 1][j + z] != '1') good = false;
          }
          if (!good) {
            len = 0;
            while (j + len < m && i + len < n && s[i + len][j + len] == '1')
              len++;
            if (len > 1 && j - len + 1 >= 0 && i + len - 1 + len - 1 < n) {
              good = true;
              for (int z(0); z < (len); z++)
                if (s[i + z][j + z] != '1') good = false;
              for (int z(0); z < (len); z++)
                if (s[i + z][j - z] != '1') good = false;
              for (int z(0); z < (len); z++)
                if (s[i + len - 1 + z][j - len + 1 + z] != '1') good = false;
              for (int z(0); z < (len); z++)
                if (s[i + len - 1 + z][j + len - 1 - z] != '1') good = false;
            }
          }
          cc = 0;
          dfs(i, j);
          if (good) {
            if (cc == len * 4 - 4) res++;
          }
        }
    cout << res << endl;
  }
  return 0;
}
