#include <bits/stdc++.h>
using namespace std;
char c[250][250];
int m, n;
int x[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int y[8] = {1, 0, -1, 0, -1, 1, -1, 1};
int no;
void makezero(int i, int j) {
  if (i < 0 || j < 0 || i >= m || j >= n || c[i][j] != '1') return;
  int z;
  c[i][j] = '2';
  no++;
  for (z = 0; z < 8; z++) makezero(i + x[z], j + y[z]);
}
int isforming(int i, int j, int l, int ind1, int ind2) {
  int a, b;
  for (a = 0; a <= l; a++) {
    for (b = ind1; b < ind2; b++) {
      if (i + x[b] * a < 0 || j + y[b] * a < 0 || i + x[b] * a >= m ||
          j + y[b] * a >= n)
        return 0;
      if (c[i + x[b] * a][j + y[b] * a] != '2') return 0;
    }
  }
  return 1;
}
int main() {
  int t, i, j;
  cin >> t;
  while (t--) {
    int coun = 0;
    cin >> m >> n;
    for (i = 0; i < m; i++) cin >> c[i];
    for (i = 0; i < m; i++) {
      for (j = 0; j < n; j++) {
        if (c[i][j] == '1') {
          no = 0;
          makezero(i, j);
          if (no % 4 || no / 4 > 250) continue;
          coun += (isforming(i, j, no / 4, 0, 2)) &&
                  (isforming(i + no / 4, j + no / 4, no / 4, 2, 4));
          coun += (isforming(i, j, no / 4, 4, 6)) &&
                  (isforming(i + no / 2, j, no / 4, 6, 8));
        }
      }
    }
    cout << coun << endl;
  }
}
