import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class CodeJam {

//	public static final String INPUT_FILE_PATH = "D://CodeJamInput.txt";
	public static final String INPUT_FILE_PATH = "D://B-large.in";
	public static final String OUTPUT_FILE_PATH = "D://CodeJamOutput.txt";

	public static List<String> readInput() {
		List<String> list = new ArrayList<String>();
		try {
			BufferedReader input = new BufferedReader(new FileReader(
					INPUT_FILE_PATH));
			try {
				String line = null;

				while ((line = input.readLine()) != null) {
					list.add(line);
				}
			} finally {
				input.close();
			}
		} catch (IOException ex) {
			ex.printStackTrace();
		}
		
		return list;
	}

	public static void writeOutput(List<String> output) {
		PrintWriter writer = null;
		try {
			writer = new PrintWriter(new FileWriter(OUTPUT_FILE_PATH));
			for (String line : output) {
				writer.println(line);
			}
			writer.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (writer != null)
				writer.close();
		}
	}
	
	public static void main(String[] args) {
		List<DanceFloor> danceFloors = DanceFloor.parseFromFile(CodeJam.readInput());
		List<String> output = new ArrayList<String>();

		for(int i = 0; i < danceFloors.size(); i++) {
			System.out.println(danceFloors.get(i));
			String line = "";
			line += "Case #" + (i + 1) + ": " + danceFloors.get(i).calculate();
			output.add(line);
		}
		
		CodeJam.writeOutput(output);
	}
}

class DanceFloor {

	private List<Integer> tripletsTotalCounts;
	private int surpriseCount;
	private int targetScore;
	private int dancersCount;

	public DanceFloor(List<Integer> tripletsTotalCounts, int surpriseCount,
			int targetScore, int dancersCount) {
		this.tripletsTotalCounts = tripletsTotalCounts;
		this.surpriseCount = surpriseCount;
		this.targetScore = targetScore;
		this.dancersCount = dancersCount;
	}

	public int calculate() {
		int result = 0;
		
		if (targetScore == 0) return dancersCount;
		
		for (int i = 0; i < tripletsTotalCounts.size(); i++) {
			int total = tripletsTotalCounts.get(i);

			if (total < (targetScore * 3 - 4)) {
				tripletsTotalCounts.remove(i--);
			} else if (total == 0) {
				tripletsTotalCounts.remove(i--);
			}
		}
		
		for (int i = 0; i < tripletsTotalCounts.size(); i++) {
			int total = tripletsTotalCounts.get(i);

			if ((surpriseCount > 0) && (total == targetScore * 3 - 4)) {
				result++;
				surpriseCount--;
				tripletsTotalCounts.remove(i--);
			} else if ((surpriseCount == 0) && (total == targetScore * 3 - 4)) {
				tripletsTotalCounts.remove(i--);
			}
		}
		
		for (int i = 0; i < tripletsTotalCounts.size(); i++) {
			int total = tripletsTotalCounts.get(i);

			if ((surpriseCount > 0) && (total == targetScore * 3 - 3)) {
				result++;
				surpriseCount--;
				tripletsTotalCounts.remove(i--);
			} else if ((surpriseCount == 0) && (total == targetScore * 3 - 3)) {
				tripletsTotalCounts.remove(i--);
			}
		}
		
		result += tripletsTotalCounts.size();
		
		return result;
	}

	public static List<DanceFloor> parseFromFile(List<String> readInput) {
		List<DanceFloor> result = new ArrayList<DanceFloor>();
		int testCaseCount = Integer.parseInt(readInput.get(0));

		for (int i = 0; i < testCaseCount; i++) {
			String line[] = readInput.get(i + 1).split(" ");

			List<Integer> totalCounts = new ArrayList<Integer>();
			for (int j = 0; j < Integer.parseInt(line[0]); j++) {
				totalCounts.add(Integer.parseInt(line[3 + j]));
			}

			result.add(new DanceFloor(totalCounts, Integer.parseInt(line[1]),
					Integer.parseInt(line[2]), Integer.parseInt(line[0])));
		}

		return result;
	}

	@Override
	public String toString() {
		return "dancersCount = " + dancersCount + "; surpriseCount = " + surpriseCount 
								 + "; targetScore = " + targetScore + "; tripletsTotalCounts" 
								 + tripletsTotalCounts.toString();
	}
}


import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

class dance {

	int single[][] = new int[4][3];
	int doublex[][] = new int[54][3];

	dance() {
		single[0][0] = 0;
		single[0][1] = 0;
		single[0][2] = 0;

		single[1][0] = 0;
		single[1][1] = 0;
		single[1][2] = 1;

		single[2][0] = 10;
		single[2][1] = 10;
		single[2][2] = 9;

		single[3][0] = 10;
		single[3][1] = 10;
		single[3][2] = 10;
	}

	int[][] gen_tuple(int num) {
		int tup[][] = new int[2][3];
		if (num % 3 == 0) {
			tup[0][0] = num / 3;
			tup[0][1] = num / 3;
			tup[0][2] = num / 3;

			tup[1][0] = num / 3 - 1;
			tup[1][1] = num / 3;
			tup[1][2] = num / 3 + 1;

		} else if (num % 3 == 1) {
			tup[0][0] = num / 3;
			tup[0][1] = num / 3;
			tup[0][2] = num / 3 + 1;

			tup[1][0] = num / 3 + 1;
			tup[1][1] = num / 3 + 1;
			tup[1][2] = num / 3 - 1;

		} else if (num % 3 == 2) {
			tup[0][0] = num / 3;
			tup[0][1] = num / 3 + 1;
			tup[0][2] = num / 3 + 1;

			tup[1][0] = num / 3;
			tup[1][1] = num / 3;
			tup[1][2] = num / 3 + 2;

		}
		return tup;
	}

	int maxx(int a, int b, int c) {
		int temp = Math.max(a, b);
		temp = Math.max(temp, c);
		return temp;

	}

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

		dance my = new dance();
		for (int i = 2; i < 29; i++) {
			int temp[][] = my.gen_tuple(i);
			// System.out.println((i - 2) * 2);
			my.doublex[(i - 2) * 2][0] = temp[0][0];
			my.doublex[(i - 2) * 2][1] = temp[0][1];
			my.doublex[(i - 2) * 2][2] = temp[0][2];

			my.doublex[(i - 2) * 2 + 1][0] = temp[1][0];
			my.doublex[(i - 2) * 2 + 1][1] = temp[1][1];
			my.doublex[(i - 2) * 2 + 1][2] = temp[1][2];

			// System.out.print(my.doublex[(i - 2) * 2][0] + " ");
			// System.out.print(my.doublex[(i - 2) * 2][1] + ",");
			// System.out.print(my.doublex[(i - 2) * 2][2] + ",");
			// System.out.print(my.doublex[(i - 2) * 2 + 1][0] + ",");
			// System.out.print(my.doublex[(i - 2) * 2 + 1][1] + ",");
			// System.out.println(my.doublex[(i - 2) * 2 + 1][2] + ",");

		}

		String Path = "C:\\Users\\Dell\\Desktop\\B-large.in";
		Scanner read = new Scanner(new File(Path));

		File file = new File("C:\\Users\\Dell\\Desktop\\out.txt");
		PrintWriter Fout = new PrintWriter(new BufferedWriter(new FileWriter(
				file)), true);

		String line = read.nextLine();
		int iter = 0;

		while (read.hasNextLine()) {
			iter = iter + 1;
			line = read.nextLine();

			String d = "[ ]+";
			String[] SplitD = line.split(d);
			for (int x = 0; x < SplitD.length; x++) {
				// System.out.println(SplitD[x]);
			}

			int N = Integer.parseInt(SplitD[0]);
			int S = Integer.parseInt(SplitD[1]);
			int p = Integer.parseInt(SplitD[2]);

			int count = 0;
			int surp = 0;

			for (int j = 0; j < N; j++) {

				int val = Integer.parseInt(SplitD[j + 3]);

				if (val < 2) {

					if (my.maxx(my.single[val][0], my.single[val][1],
							my.single[val][2]) >= p) {
						count += 1;
					}

				} else if (val > 28) {
					if (my.maxx(my.single[val - 27][0], my.single[val - 27][1],
							my.single[val - 27][2]) >= p) {
						count += 1;
					}
				} else {
					if (my.maxx(my.doublex[(val - 2) * 2][0],
							my.doublex[(val - 2) * 2][1],
							my.doublex[(val - 2) * 2][2]) >= p) {
						count += 1;
					} else if (my.maxx(my.doublex[(val - 2) * 2 + 1][0],
							my.doublex[(val - 2) * 2 + 1][1],
							my.doublex[(val - 2) * 2 + 1][2]) >= p) {
						surp += 1;
					}
				}
			}

			if (surp > S) {
				count = count + S;
			} else {
				count = count + surp;
			}
			String output_str = "Case #" + iter + ": " + count;
			Fout.println(output_str);
		}
		read.close();
	}

}