#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
void __never(int a) { printf("\nOPS %d", a); }
bool M[256][256];
int n, m;
char ch[500];
inline bool it_is(int x, int y, string str) {
  if (x < 1 || y < 1 || x > n || y > m) return false;
  int i = 0;
  for (int a = (x - 1); a <= (x + 1); a++)
    for (int b = (y - 1); b <= (y + 1); b++)
      if (M[a][b] != (str[i++] == '1')) return false;
  return true;
}
void sol() {
  int ans = 0;
  for (int a = (1); a <= (n); a++)
    for (int b = (1); b <= (m); b++) {
      if (it_is(a, b, "000011010")) {
        for (int c = (b + 2); c <= (m); c++)
          if (c <= m)
            if (it_is(a, c, "000110010")) {
              int sz = c - b;
              if (!it_is(a + sz, b, "010011000")) break;
              if (!it_is(a + sz, b + sz, "010110000")) break;
              bool flag = true;
              for (int d = (2); d <= (sz - 2); d++) {
                if (!it_is(a + d, b, "010010010")) {
                  flag = false;
                  break;
                }
                if (!it_is(a + d, b + sz, "010010010")) {
                  flag = false;
                  break;
                }
                if (!it_is(a + sz, b + d, "000111000")) {
                  flag = false;
                  break;
                }
              }
              if (!flag) break;
              ans++;
              break;
            } else if (!it_is(a, c, "000111000")) {
              if (!(it_is(a, c, "000111001") && it_is(a, c + 1, "000110010")))
                break;
            }
      }
      if (it_is(a, b, "001010001")) {
        for (int c = (1); c <= (m); c++)
          if (a - c >= 1 && b + c <= m)
            if (it_is(a - c, b + c, "000010101")) {
              if (!it_is(a + c, b + c, "101010000")) break;
              if (!it_is(a, b + c + c, "100010100")) break;
              bool flag = true;
              for (int d = (1); d <= (c - 1); d++) {
                if (!it_is(a + d, b + d, "100010001")) {
                  flag = false;
                  break;
                }
                if (!it_is(a + d, b + c + c - d, "001010100")) {
                  flag = false;
                  break;
                }
                if (!it_is(a - d, b + c + c - d, "100010001")) {
                  flag = false;
                  break;
                }
              }
              if (!flag) break;
              ans++;
              break;
            } else if (!it_is(a - c, b + c, "001010100"))
              break;
      }
      if (it_is(a, b, "000011011")) {
        if (it_is(a + 1, b, "011011000"))
          if (it_is(a, b + 1, "000110110"))
            if (it_is(a + 1, b + 1, "110110000")) ans++;
      }
    }
  printf("%d\n", ans);
}
int main() {
  int t;
  scanf("%d", &t);
  for (int a = (1); a <= (t); a++) {
    scanf("%d%d", &n, &m);
    for (int b = (1); b <= (n); b++) {
      scanf("%s", ch);
      for (int c = (0); c <= (m - 1); c++) M[b][c + 1] = (ch[c] == '1');
    }
    sol();
    for (int b = (1); b <= (n); b++)
      for (int c = (1); c <= (m); c++) M[b][c] = false;
  }
  return 0;
}
