#include <cstdio>
#include <algorithm>

#define N 5

using namespace std;

int
main ( )
{
  int n;
  int i, j;

  scanf ( "%d", &n );
  while ( n-- )
  {
    int d[ N ][ N + 1 ] = { };
    int res = 0;

    for ( i = 0; i < N; ++i )
    for ( j = 0; j < N; ++j )
    {
      scanf ( "%d", &d[ i ][ j ] );
    }

    for ( i = 1; i < N; ++i )
    for ( j = 0; j < N; ++j )
    {
      if ( d[ i ][ j ] )
      {
        d[ i ][ j ] += d[ i - 1 ][ j ];
      }
    }

    for ( i = 0; i < N; ++i )
    {
      int s[ N ], sp = 0;

      for ( j = 0; j <= N; ++j )
      {
        while ( sp
            && d[ i ][ s[ sp - 1 ] ] > d[ i ][ j ] )
        {
          res = max ( res, ( j - s[ sp - 1 ] ) * d[ i ][ s[ sp - 1 ] ] );
          --sp;
        }
        s[ sp++ ] = j;
      }
    }

    printf ( "%d\n", res );
  }

  return ( 0 );
}