#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

int main() {
	int m; std::cin >> m;
	for (auto i = 0; i < m; ++i) {
		std::vector<std::vector<int>> state(5, std::vector<int>(5)); for (auto& line : state) for (auto& cell : line) std::cin >> cell;
		int max = 0;
		for (auto lower = 0; lower < 5; ++lower) for (auto higher = lower; higher < 5; ++higher) {
			auto height = higher - lower + 1;
			for (auto left = 0; left < 5; ++left) for (auto right = left; right < 5; ++right) {
				auto width = right - left + 1;
				int count = 0;
				for (auto h = 0; h < height; ++h) for (auto w = 0; w < width; ++w) {
					if (state[lower + h][left + w] == 1) {
						++count;
					}
				}
				if (count == height * width) max = std::max(max, count);
			}
		}
		std::cout << max << std::endl;
	}
}

