/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Dancing
 * Jason Bradley Nel
 * 16287398
 */
import java.io.*;

public class Dancing {

    public static void main(String[] args) {

        In input = new In("input.txt");
        int T = Integer.parseInt(input.readLine());

        for (int i = 0; i < T; i++) {
            System.out.printf("Case #%d: ", i + 1);
            int N = input.readInt();
            int s = input.readInt();
            int p = input.readInt();
            int c = 0;//counter for >=p cases
            //System.out.printf("N: %d, S: %d, P: %d, R: ", N, s, p);
            
            for (int j = 0; j < N; j++) {
                
                int score = input.readInt();
                int q = score / 3;
                int m = score % 3;
                //System.out.printf("%2d (%d, %d) ", scores[j], q, m);
                                
                switch (m) {
                    case 0:
                        if (q >= p) {
                            c++;
                        } else if (((q + 1) == p) && (s > 0) && (q != 0)) {
                            c++;
                            s--;
                        }
                        break;
                    case 1:
                        if (q >= p) {
                            c++;
                        } else if ((q + 1) == p) {
                            c++;
                        }
                        break;
                    case 2:
                        if (q >= p) {
                            c++;
                        } else if ((q + 1) == p) {
                            c++;
                        } else if (((q + 2) == p) && (s > 0)) {
                            c++;
                            s--;
                        }
                        break;
                }
            }
            //System.out.printf("Best result of %d or higher: ", p);
            System.out.println(c);
        }


    }
}

package codejam;

import java.util.*;
import java.io.*;

public class DancingWithTheGooglers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int N = Integer.parseInt(parts[0]);
			int S = Integer.parseInt(parts[1]);
			int p = Integer.parseInt(parts[2]);
			int[] scores = new int[N];
			
			for (int i = 0; i < N; ++i)
				scores[i] = Integer.parseInt(parts[3 + i]);
			
			int max = 0;
			for (int i = 0; i < (1 << N); ++i) {
				if (Integer.bitCount(i) == S) {
					int cnt = 0;
					for (int j = 0; j < N; ++j) {
						int mod = scores[j] % 3;
						int score = scores[j] / 3;
						if (mod == 1 || mod == 2)
							++score;
						if ((i & (1 << j)) != 0) { // if surprising
							if (scores[j] > 1 && (mod == 0 || mod == 2))
								++score;
						}
						score = Math.min(score, 10);
						if (score >= p)
							++cnt;
						//System.out.println(score);
					}
					max = Math.max(max, cnt);
				}
			}
			
			out.println("Case #" + t + ": " + max);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}
