/*
 * 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 dancingwiththegooglers;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class DancingWithTheGooglers {

	
	public static void main(String[] args) throws IOException {
		

		BufferedReader br=new BufferedReader(new FileReader(new File("./dancingwiththegooglers/b-small-attempt1.in")));
		BufferedWriter bw=new BufferedWriter(new FileWriter(new File("./dancingwiththegooglers/small1.out")));
		
		int numberOfCase=Integer.parseInt(br.readLine());
		
		StringBuilder out=new StringBuilder();
		
		for(int i=1;i<=numberOfCase;i++){
			int count=0;
			out.append("Case #"+i+": ");
			
			String[]input=br.readLine().split(" ");
			
			int surprising=Integer.parseInt(input[1]);
			int goal=Integer.parseInt(input[2]);
			int googlers=Integer.parseInt(input[0]);
			for(int j=3;j<3+googlers;j++){
				
				int result=check(Integer.parseInt(input[j]),goal,surprising);
				if(result==0){
					count++;
					surprising--;
				}
				if(result==1)
					count++;
				
					
				
			}
			
			
			
			out.append(count);
			if(i<numberOfCase)
				out.append("\n");			
			
			
		}
		bw.write(out.toString());
		br.close();
		bw.close();
		

	}
	
	/*
	 * return  1 - possible to achieve goal and is not surprising
	 *         0 - possible to achieve goal and is surprising
	 *         -1 - impossible to achieve goal
	 */
	public static int check(int totalScore,int goal,int surprising){
		
		if(totalScore<goal)
			return -1;
		
		int r=totalScore%3;
		int max=-1;
		if(r==0)
			max=totalScore/3;
		if(r==1)
			max=(int)Math.ceil(totalScore/3.0);
		if(r==2)
			max=(int)Math.ceil(totalScore/3.0);
		
		if(max<goal)
			if(surprising==0)
				return -1;
			else{
				if(totalScore>=goal+(goal-2)+(goal-2))
					return 0;
				else
					return -1;
			}
		else
			return 1;
		
	}

}
