n = gets.to_i
mask = Array.new(26).map { [] }

(0..4).each{|i|
	(0..4).each{|j|
		(0..4-i).each{|h|
			(0..4-j).each{|w|
				m  = 0	
				(i..i+h).each{|y|
					(j..j+w).each{|x|
						m |= 1 << 5*y+x
					}
				}
				mask[(w+1)*(h+1)] << m
			}
		}
	}
}

n.times {
	bits = (1..5).map{gets.split.map &:to_i}.flatten.inject(0){|s, i| (s << 1) | i}
	max = 0
	25.downto(1){|area|
		mask[area].each{|m|
			if bits & m == m
				max = area
				break
			end
		}
		break if max > 0
	}
	p max
	gets
}