// Arup Guha
// 5/18/2018 - Written for practice
// 2018 Google Code Jam Jam Round 1C Problem C: Ant Stack
// Note: I have no idea why this passed the large data??? Looks like O(n^2)...
// I just read the editorial...I guess my intuition about the ant weights and how
// quickly they are forced to increase was just plain wrong =)

import java.util.*;
import java.io.*;

public class Solution {

	public static int n;
	public static long[] w;

	public static void main(String[] args) throws Exception {

		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		int nC = Integer.parseInt(stdin.readLine().trim());

		// Process each case.
		for (int loop=1; loop<=nC; loop++) {

			// Get the input.
			n = Integer.parseInt(stdin.readLine().trim());
			w = new long[n];
			StringTokenizer tok = new StringTokenizer(stdin.readLine());
			for (int i=0; i<n; i++)
				w[i] = Long.parseLong(tok.nextToken());

			// In DP for each number of ants x, store min weight...
			long[] dp = new long[n+1];
			Arrays.fill(dp, -1);
			dp[0] = 0;
			for (int i=0; i<n; i++) {

				int lim = 0;
				while (dp[lim] != -1) lim++;

				// Try building off each prior state.
				for (int j=lim; j>0; j--) {
					if (dp[j-1] > 6*w[i]) continue;
					if (dp[j] == -1 || dp[j-1]+w[i] < dp[j])
						dp[j] = dp[j-1]+w[i];
				}
			}

			// Find largest value filled in.
			int res = 0;
			for (int i=0; i<=n; i++)
				if (dp[i] != -1)
					res = i;

			System.out.println("Case #"+loop+": "+res);
		}
	}

}