#include <bits/stdc++.h>
constexpr int MAXN = 255;
using namespace std;
int testCase, n, m, cnt, tot;
int Cnt1, Cnt2, Cnt3, Cnt4;
int mp[MAXN][MAXN], vis[MAXN][MAXN], cpy[MAXN][MAXN];
int dr[8] = {1, 1, 1, 0, 0, -1, -1, -1};
int dc[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
inline void clear(int r, int c) {
  mp[r][c] = 0, tot++;
  for (int i = 0; i < 8; i++) {
    int toR = r + dr[i], toC = c + dc[i];
    if (toR < 1 || toR > n || toC < 1 || toC > m) continue;
    if (mp[toR][toC]) clear(toR, toC);
  }
}
inline int check1(int r, int c) {
  Cnt1 = Cnt2 = Cnt3 = Cnt4 = 0;
  while (mp[r][c])
    if (r + 1 > n || !mp[r + 1][c])
      break;
    else
      r++, Cnt1++;
  while (mp[r][c])
    if (c + 1 > m || !mp[r][c + 1])
      break;
    else
      c++, Cnt2++;
  while (mp[r][c])
    if (r - 1 < 1 || !mp[r - 1][c])
      break;
    else
      r--, Cnt3++;
  while (mp[r][c])
    if (c - 1 < 1 || !mp[r][c - 1])
      break;
    else
      c--, Cnt4++;
  if (Cnt1 == Cnt2 && Cnt2 == Cnt3 && Cnt3 == Cnt4) return Cnt1;
  return false;
}
inline int check2(int r, int c) {
  Cnt1 = Cnt2 = Cnt3 = Cnt4 = 0;
  while (mp[r][c])
    if (r + 1 > n || c - 1 < 1 || !mp[r + 1][c - 1])
      break;
    else
      r++, c--, Cnt1++;
  while (mp[r][c])
    if (r + 1 > n || c + 1 > m || !mp[r + 1][c + 1])
      break;
    else
      r++, c++, Cnt2++;
  while (mp[r][c])
    if (r - 1 < 1 || c + 1 > m || !mp[r - 1][c + 1])
      break;
    else
      r--, c++, Cnt3++;
  while (mp[r][c])
    if (r - 1 < 1 || c - 1 < 1 || !mp[r - 1][c - 1])
      break;
    else
      r--, c--, Cnt4++;
  if (Cnt1 == Cnt2 && Cnt2 == Cnt3 && Cnt3 == Cnt4) return Cnt1;
  return false;
}
int main() {
  cin >> testCase;
  while (testCase--) {
    cin >> n >> m;
    cnt = 0;
    for (int i = 1; i <= n; i++) {
      getchar();
      for (int j = 1; j <= m; j++) mp[i][j] = cpy[i][j] = getchar() - '0';
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (mp[i][j]) {
          tot = 0;
          int num1 = check1(i, j);
          int num2 = check2(i, j);
          clear(i, j);
          if (num1 * 4 == tot || num2 * 4 == tot) cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
