#include <bits/stdc++.h>
using namespace std;
char d[257][257] = {};
bool check1(int x, int y, int sz, char val) {
  for (int i = 0; i <= sz; i++)
    if (d[x + i][y] != val || d[x + i][y + sz] != val ||
        d[x + sz][y + i] != val || d[x][y + i] != val)
      return false;
  return true;
}
void fill1(int x, int y, int sz) {
  for (int i = 0; i <= sz; i++) {
    if (d[x + i][y] == '1') d[x + i][y] = '2';
    if (d[x + i][y + sz] == '1') d[x + i][y + sz] = '2';
    if (d[x][y + i] == '1') d[x][y + i] = '2';
    if (d[x + sz][y + i] == '1') d[x + sz][y + i] = '2';
  }
}
int try1(int x, int y) {
  if (d[x - 1][y] != '0' || d[x][y - 1] != '0' || d[x - 1][y - 1] != '0') {
    d[x][y] = '2';
    return 0;
  }
  if (d[x + 1][y] != '1' && d[x][y + 1] != '1') return 0;
  for (int i = 1;; i++) {
    if (d[x + i][y] != '1' || d[x][y + i] != '1') {
      return 0;
    }
    if (d[x + i][y + 1] == '1' || d[x + 1][y + i] == '1') {
      if (check1(x, y, i, '1') && check1(x + 1, y + 1, i - 2, '0') &&
          check1(x - 1, y - 1, i + 2, '0'))
        return 1;
      else {
        return 0;
      }
    }
  }
  return 0;
}
void fill2(int x, int y, int sz) {
  for (int i = 0; i <= sz; i++) {
    if (d[x + i][y + i] == '1') d[x + i][y + i] = '2';
    if (d[x + i][y - i] == '1') d[x + i][y - i] = '2';
    if (d[x - i + sz * 2][y + i] == '1') d[x - i + sz * 2][y + i] = '2';
    if (d[x - i + sz * 2][y - i] == '1') d[x - i + sz * 2][y - i] = '2';
  }
}
bool check2(int x, int y, int sz, char val) {
  for (int i = 0; i <= sz; i++) {
    if (d[x + i][y + i] != val || d[x + i][y - i] != val ||
        d[x - i + sz * 2][y + i] != val || d[x - i + sz * 2][y - i] != val)
      return false;
  }
  return true;
}
bool check3(int x, int y, int sz, char val) {
  for (int i = 1; i < sz; i++) {
    if (d[x + i][y + i] != val || d[x + i][y - i] != val ||
        d[x - i + sz * 2][y + i] != val || d[x - i + sz * 2][y - i] != val)
      return false;
  }
  return true;
}
int try2(int x, int y) {
  if (d[x - 1][y] != '0' || d[x][y - 1] != '0' || d[x - 1][y - 1] != '0' ||
      d[x][y + 1] != '0' || d[x - 1][y - 1] != '0') {
    d[x][y] = '2';
    return 0;
  }
  for (int i = 1;; i++) {
    if (d[x + i][y + i] != '1' || d[x + i][y - i] != '1') {
      return 0;
    }
    if (d[x + i + 1][y - i + 1] == '1' || d[x + i + 1][y + i - 1] == '1') {
      if (check2(x, y, i, '1') && check2(x - 1, y, i + 1, '0') &&
          check3(x - 2, y, i + 2, '0') && check2(x + 1, y, i - 1, '0') &&
          check2(x + 2, y, i - 2, '0')) {
        return 1;
      } else {
        return 0;
      }
    }
  }
  return 0;
}
int main() {
  int t;
  scanf("%d", &t);
  for (int e = 0; e < t; e++) {
    int n, m;
    scanf("%d %d", &n, &m);
    memset(d, '0', sizeof d);
    for (int i = 2; i <= n + 1; i++) {
      scanf("%s", &d[i][2]);
      d[i][m + 2] = '0';
      d[i][m + 3] = '0';
    }
    int sum = 0;
    for (int i = 2; i <= n + 1; i++) {
      for (int u = 2; u <= m + 1; u++) {
        if (d[i][u] == '1') {
          sum += try1(i, u);
          sum += try2(i, u);
        }
      }
    }
    cout << sum << endl;
  }
  return 0;
}
