package code12.qualification;

import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;

public class B {
	public static String solve(int N, int S, int p, int[] t) {
		
		// 3a 		-> (a, a, a), *(a - 1, a, a + 1)
		// 3a + 1	-> (a, a, a + 1), *(a - 1, a + 1, a + 1)
		// 3a + 2	-> (a, a + 1, a + 1), *(a, a, a + 2)
		
		int numPNoS = 0;
		int numPWithS = 0;
		
		for (int i = 0; i < N; i++) {
			int a = (int)Math.floor(t[i] / 3);
			int r = t[i] % 3;
			
			switch (r) {
			case 0:
				if (a >= p) {
					numPNoS++;
				} else if (a + 1 >= p && a - 1 >= 0) {
					numPWithS++;
				}
				break;
			case 1:
				if (a >= p || a + 1 >= p) {
					numPNoS++;
				}
				break;
			case 2:
				if (a >= p || a + 1 >= p) {
					numPNoS++;
				} else if (a + 2 >= p) {
					numPWithS++;
				}
				break;
			}
		}
		
		return "" + (numPNoS + Math.min(S, numPWithS));
	}

	public static void main(String[] args) throws Exception {
		// file name
		//String fileName = "Sample";
		//String fileName = "B-small";
		String fileName = "B-large";
		
		// file variable
		File inputFile = new File(fileName + ".in");
		File outputFile = new File(fileName + ".out");
		Scanner scanner = new Scanner(inputFile);
		FileWriter writer = new FileWriter(outputFile);

		// problem variable
		int totalCase;
		int N, S, p;
		int[] t;

		// get total case
		totalCase = scanner.nextInt();

		for (int caseIndex = 1; caseIndex <= totalCase; caseIndex++) {
			// get input
			N = scanner.nextInt();
			S = scanner.nextInt();
			p = scanner.nextInt();
			t = new int[N];
			
			for (int i = 0; i < N; i++) {
				t[i] = scanner.nextInt();
			}
			
			String output = "Case #" + caseIndex + ": " + solve(N, S, p, t);
			System.out.println(output);
			writer.write(output + "\n");
		}
		scanner.close();
		writer.close();
	}
}

import java.io.*;

public class DancingWithGooglers {

	static int caseNumber;
	static int totalCases;
	
	public static void main(String[] args) throws Exception {
		
		caseNumber = 1;

		File fileIn = new File("C:\\GCJ\\DancingWithGooglers\\B-large.in");
		FileInputStream fileInputStream = null;
		BufferedInputStream inputStream = null;
		BufferedReader reader = null;
		Writer out;
		
		String newLine = System.getProperty("line.separator");
		
		String fileOutPath = "C:\\GCJ\\DancingWithGooglers\\outputLarge.txt";
		File fileOut = new File(fileOutPath);
		if (! fileOut.createNewFile()){
			fileOut.delete();
			fileOut.createNewFile();
		}
		
		out = new OutputStreamWriter(new FileOutputStream(fileOutPath), "US-ASCII");
		
		
		StringBuilder builder = new StringBuilder();

		try {
			fileInputStream = new FileInputStream(fileIn);

			// Here BufferedInputStream is added for fast reading.
			inputStream = new BufferedInputStream(fileInputStream);
			reader = new BufferedReader(new InputStreamReader(inputStream));

			totalCases = Integer.parseInt(reader.readLine());
			while (caseNumber <= totalCases){
				builder.append(handleTestCase(reader));
				builder.append(newLine);
				caseNumber++;
			}
			
			
			// dispose all the resources after using them.
			fileInputStream.close();
			inputStream.close();
			reader.close();

		} catch (Exception e) {
			e.printStackTrace();
		} 
		System.out.print(builder.toString());
		out.write(builder.toString());
		out.close();
	}
	
	public static String handleTestCase(BufferedReader reader) throws IOException{
		String[] splitLine = reader.readLine().split(" ");
		int[] ints = stringArrayToIntArray(splitLine);
		int numScores = ints[0];
		int numSurprises = ints[1];
		int goal = ints[2];
		
		int surprisesLeft = numSurprises;
		int metGoal = 0;
		for(int i = 3; i < ints.length; i++){
			//Base cases
			if(ints[i] == 0) {
				if(goal == 0)
					metGoal++;
			}
			
			else if(ints[i] == 1){
				if(goal == 1)
					metGoal++;
			}
			//Handles if the number is divisible by 3
			//If the average is >= the goal, it is trivially meeting the goal
			//If you allow for a surprise, the max can grow by 1
			else if(ints[i] % 3 == 0){
				if(ints[i] / 3 >= goal)
					metGoal++;
				else if ( ints[i] / 3 == goal - 1){
					if(surprisesLeft > 0) {
						surprisesLeft--;
						metGoal++;
					}
				}
			}
			
			//The value of the maximum doesn't change even with a surprise with ints[i] % 3 ==1
			//So I don't even evaluate it here and worry about deducting available surprises
			else if(ints[i] % 3 == 1){
				if(ints[i] / 3 >= goal-1)
					metGoal++;
			}
			
			//Value of the maximum with % 3 == 2 is one above the average by default
			//Allowing for a surprise allows for it to be one higher
			else if(ints[i] % 3 == 2){ //Unecessary "if" statement kept to remind about the last case
				if(ints[i] / 3 >= goal-1)
					metGoal++;
				else if(ints[i] / 3 == goal - 2){
					if(surprisesLeft > 0) {
						surprisesLeft--;
						metGoal++;
					}
				}
			}
			
		}
		
		if(surprisesLeft > 0)
			System.out.println("Surprises were left: "+surprisesLeft+" on case "+caseNumber);
		return "Case #"+caseNumber+": "+metGoal;
	}
	
	public static int[] stringArrayToIntArray(String[] input){
		int[] ints = new int[input.length];
		for (int i = 0; i < input.length; i++){
			ints[i] = Integer.parseInt(input[i]);
		}
		return ints;
	}
}
