#include <stdio.h>
#include <stdlib.h>
#define N 5

int areaCount(char a[][N + 1], int f, int t)
{
  int r = 0, i, j;

  for (i = f / N; i <= t / N ; ++i) {
    for (j = f % N; j <= t % N ; ++j) {
      if (a[i][j] == '1')++r;
      else return 0;
    }
  }

  return r;
}

void func(char a[][N + 1])
{
  int f, t, w, max = 0;

  for (f = 0; f < N * N; ++f) {
    for (t = f + 1; t < N * N; ++t) {
      w = areaCount(a, f, t);
      if (max < w)max = w;
    }
  }
  printf("%d\n", max);
}

int main()
{
  char buf[100], a[N][N + 1];

  fgets(buf, 100, stdin);
  int n = atoi(buf);
  while (n--) {
    {
      int i = 0;
      while (fgets(buf, 100, stdin)) {
        if (buf[0] == '\n')break;
        sprintf(a[i++], "%s", buf);
      }
      func(a);
    }
  }

  return 0;
}
