#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXW = 7, W = 5;

int main()
{
	int m; cin >> m;
	while( m -- )
	{
		int tile[MAXW][MAXW] = {};
		int w[MAXW][MAXW] = {};
		int dp[MAXW][MAXW] = {};
		rep(j,W)rep(i,W) cin >> tile[i+1][j+1];

		rep(j,W)rep(i,W) w[i+1][j+1] = (w[i][j+1] + 1) * tile[i+1][j+1];

		//rep(j,W){ rep(i,W) cout << w[i+1][j+1] << " "; cout << endl;}

		int width = 0;
		rep(j,W)rep(i,W)
		{
			width = 5;
			for(int k = 0; j - k >= 0;k++)
			{
				width = min(width, w[i+1][j+1 - k]);
				dp[i][j] = max(dp[i][j], width * (k + 1));
			}
		}
		int ans = 0;
		rep(j,W)rep(i,W) ans = max(ans, dp[i][j]);
		cout << ans << endl;
	}

	return 0;
}