public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		int times = Integer.parseInt(in.readLine().trim());
		for (int t = 0; t < times; t++) {
			in.readLine();
			String firstLine = in.readLine().trim();
			int size = firstLine.length();
			m = new char[size][size];
			m[0] = firstLine.toCharArray();
			for (int j = 1; j < size; j++)
				m[j] = in.readLine().trim().toCharArray();
			area = getMaxRectangleSum();
			if (t != 0)
				out.append("\n");
			out.append(area + "\n");
		}
		System.out.print(out);
	}