public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "", data[];
		StringBuilder out = new StringBuilder();
		while ((line = in.readLine()) != null && line.length() != 0) {
			int test = Integer.parseInt(line.trim());
			String name;
			for (int i = 0; i < test; i++) {
				data = in.readLine().trim().split(" ");
				name = data[0];
				rows = Integer.parseInt(data[1].trim());
				cols = Integer.parseInt(data[2].trim());
				m = new int[rows][cols];
				min = new int[rows][cols];
				for (int j = 0; j < m.length; j++)
					m[j] = retInts(in.readLine());
				int max = 0;
				for (int r = 0; r < m.length; r++) 
					for (int c = 0; c < cols; c++) {
						if(min[r][c]==0)
							cal(r, c, 0);
						max = Math.max(max, min[r][c]);
					}
				out.append(name+": "+max+"\n");
			}
		}
		System.out.print(out);
	}