#include <stdio.h>
#define FIELD(y, x) ((y) >= 0 && (x) >= 0 ? field[y][x] : 0)
#define SIZE 5

int field[SIZE][SIZE];

void dump()
{
    int x, y;

    for(y = 0; y < SIZE; y++)
    {
        for(x = 0; x < SIZE; x++) printf("%d ", field[y][x]);
        puts("");
    }
}

int main(void)
{
    int n, x, y, x2, y2, max, t1, t2;

    scanf("%d", &n);

    while(n--)
    {
        for(y = 0; y < SIZE; y++)
            for(x = 0; x < SIZE; x++)
                scanf("%d", &field[y][x]);

        /* top -> bottom */
        for(y = 1; y < SIZE; y++)
            for(x = 0; x < SIZE; x++)
                field[y][x] += field[y - 1][x];

        /* left -> right */
        for(x = 1; x < SIZE; x++)
            for(y = 0; y < SIZE; y++)
                field[y][x] += field[y][x - 1];

        dump();

        /* search */
        max = 0;
        for(x = 0; x < SIZE; x++)
            for(y = 0; y < SIZE; y++)
                for(y2 = y; y2 < SIZE; y2++)
                    for(x2 = x; x2 < SIZE; x2++)
                    {
                        t1 = (x2 - x + 1) * (y2 - y + 1);
                        t2 = field[y2][x2]
                             - FIELD(y - 1, x2)
                             - FIELD(y2, x - 1)
                             + FIELD(y - 1, x - 1);
                        if((t2 == t1 || t2 == 0) && (max < t1)) max = t1;
                    }

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

    return 0;
}