#include <bits/stdc++.h>
using namespace std;
template <typename T>
int size(const T& c) {
  return (int)c.size();
}
template <typename T>
void remin(T& a, const T& b) {
  if (b < a) a = b;
}
template <typename T>
void remax(T& a, const T& b) {
  if (b > a) a = b;
}
template <typename T>
T abs(T x) {
  return x < 0 ? -x : x;
}
template <typename T>
T sqr(T x) {
  return x * x;
}
int n, m;
char a[250][251];
vector<pair<int, int> > pts;
bool check1() {
  if (size(pts) % 4) return false;
  int si = pts[0].first, sj = pts[0].second;
  int n = size(pts) / 4;
  int p = 0;
  for (int i(0), _b(n); i <= _b; ++i)
    if (pts[p++] != pair<int, int>(si, sj + i)) return false;
  for (int i(1), _b(n - 1); i <= _b; ++i) {
    if (pts[p++] != pair<int, int>(si + i, sj)) return false;
    if (pts[p++] != pair<int, int>(si + i, sj + n)) return false;
  }
  for (int i(0), _b(n); i <= _b; ++i)
    if (pts[p++] != pair<int, int>(si + n, sj + i)) return false;
  assert(p == size(pts));
  return true;
}
bool check2() {
  if (size(pts) % 4) return false;
  int si = pts[0].first, sj = pts[0].second;
  int n = size(pts) / 4;
  int p = 0;
  if (pts[p++] != pair<int, int>(si, sj)) return false;
  for (int i(1), _b(n); i <= _b; ++i) {
    if (pts[p++] != pair<int, int>(si + i, sj - i)) return false;
    if (pts[p++] != pair<int, int>(si + i, sj + i)) return false;
  }
  for (int i(1), _b(n - 1); i <= _b; ++i) {
    if (pts[p++] != pair<int, int>(si + n + i, sj - n + i)) return false;
    if (pts[p++] != pair<int, int>(si + n + i, sj + n - i)) return false;
  }
  if (pts[p++] != pair<int, int>(si + n + n, sj)) return false;
  assert(p == size(pts));
  return true;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i(0), _n(n); i < _n; ++i) scanf("%s", a[i]);
    int res = 0;
    for (int i(0), _n(n); i < _n; ++i)
      for (int j(0), _n(m); j < _n; ++j)
        if (a[i][j] == '1') {
          pts.clear();
          pts.push_back(pair<int, int>(i, j));
          a[i][j] = '0';
          for (int k = 0; k < size(pts); ++k) {
            for (int ni(pts[k].first - 1), _b(pts[k].first + 1); ni <= _b; ++ni)
              for (int nj(pts[k].second - 1), _b(pts[k].second + 1); nj <= _b;
                   ++nj)
                if (a[ni][nj] == '1') {
                  pts.push_back(pair<int, int>(ni, nj));
                  a[ni][nj] = '0';
                }
          }
          sort((pts).begin(), (pts).end());
          if (check1() || check2()) ++res;
        }
    printf("%d\n", res);
  }
  exit(0);
}
