public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		StringBuilder out = new StringBuilder();
		int boards = in.nextInt();
		v = new int[8][8];
		allSol = new int[93][9];
		nsol = 0;
		board = new int[9];
		queens(1);
		for (int i = 0; i < boards; i++) {
			for (int j = 0; j < 8; j++)
				for (int k = 0; k < 8; k++)
					v[j][k] = in.nextInt();
			int ans = 0, curSum = 0;
			for (int j = 0; j < nsol; j++) {
				curSum = 0;
				for (int k = 1; k <= 8; k++) 
					curSum+=v[k-1][allSol[j][k]-1];
				ans = Math.max(ans, curSum);
			}
			out.append(String.format("%5d", ans) + "\n");
		}
		System.out.print(out);
	}