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.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class Solution {
	static final boolean DBG = false;

	// x x x s= 3x
	// x x x+1 s= 3x +1
	// x x x-1 s= 3x -1
	// x x+1 x+1 s= 3x +2
	// x x-1 x-1 s= 3x-2

	public static void main(String[] args) {

		AllNormal allNormal = new AllNormal();
		AllSurprising allSurprising = new AllSurprising();

		Scanner sc = new Scanner(System.in);
		long dStart = System.currentTimeMillis();
		StringBuilder sbout = new StringBuilder();

		int T = sc.nextInt();
		for (int i = 1; i <= T; i++) {
			Task one = new Task(sc, allNormal, allSurprising);
			int res = one.getSolution();
			sbout.append("Case #");
			sbout.append(i);
			sbout.append(": ");
			sbout.append(res);
			sbout.append('\n');
		}

		if (DBG) {
			sbout.append("time :");
			sbout.append(System.currentTimeMillis() - dStart);
		}
		System.out.print(sbout.toString());

	}

	static class Task {
		int N; // number of people
		int S; // Surprising Triplets;
		int p; // ? of N with best result >= p

		ArrayList<OnePerson> persons = new ArrayList<OnePerson>();
		String original = "";

		public Task(Scanner sc, AllNormal allNormal, AllSurprising allSurprising) {
			N = sc.nextInt();
			S = sc.nextInt();
			p = sc.nextInt();

			original = N + " " + S + " " + p + ", ";
			for (int i = 0; i < N; i++) {
				OnePerson one = new OnePerson(sc.nextInt());
				one.setHowItCan(allNormal, allSurprising, p);
				persons.add(one);
				original += " " + one.sum;
			}
		}

		int getSolution() {
			int canNormal = 0;
			int canWithSurprising = 0;
			for (OnePerson one : persons) {
				if (one.canHaveWithNormal) {
					canNormal++;
				} else {
					if (one.canWithSurprising)
						canWithSurprising++;
				}
			}

			return canNormal + Math.min(canWithSurprising, S);
		}
	}

	static class OnePerson {
		int sum = 0;
		boolean canHaveWithNormal = false; // can have best >= p without
											// surprising rating

		boolean canWithSurprising = false;

		public OnePerson(int sum) {
			this.sum = sum;
		}

		void setHowItCan(AllNormal allNormal, AllSurprising allSurprising, int p) {
			canHaveWithNormal = (allNormal.all.get(this.sum).best >= p);
			canWithSurprising = allSurprising.canBeSurprisingWithBestGreater(
					this.sum, p);
		}

	}

	static class AllNormal {
		HashMap<Integer, NormalRating> all = new HashMap<Integer, Solution.NormalRating>();

		public AllNormal() {
			for (int i = 0; i <= 10; i++) {
				addOne(new NormalRating(3 * i, i, i));
				addOne(new NormalRating(3 * i + 1, i + 1, i));
				addOne(new NormalRating(3 * i - 1, i, i - 1));
				addOne(new NormalRating(3 * i + 2, i + 1, i));
				addOne(new NormalRating(3 * i - 2, i, i - 1));
			}
		}

		void addOne(NormalRating one) {
			if (one.isValid() && !all.containsKey(one.sum)) {
				all.put(one.sum, one);
			}
		}

		void printAll() {
			ArrayList<NormalRating> vals = new ArrayList<Solution.NormalRating>();
			vals.addAll(all.values());
			Collections.sort(vals);
			for (NormalRating one : vals) {
				one.printLn();
			}
		}
	}

	static class NormalRating implements Comparable<NormalRating> {
		int sum = 0;
		int best = 0;
		int min = 0;

		public NormalRating(int sum, int best, int min) {
			this.sum = sum;
			this.best = best;
			this.min = min;
		}

		boolean isValid() {
			return (sum >= 0) && (best >= 0) && (min >= 0) && (best <= 10);
		}

		void printLn() {
			System.out.println("s: " + sum + "  b: " + best + " m: " + min);
		}

		@Override
		public int compareTo(NormalRating other) {
			return (new Integer(sum)).compareTo(new Integer(other.sum));
		}

	}

	static class AllSurprising {
		ArrayList<SurprisingRating> items = new ArrayList<Solution.SurprisingRating>();

		public AllSurprising() {
			for (int i = 0; i <= 8; i++) {
				addOne(new SurprisingRating(3 * i + 2, i + 2));
				addOne(new SurprisingRating(3 * i + 3, i + 2));
				addOne(new SurprisingRating(3 * i + 4, i + 2));

			}
		}

		void addOne(SurprisingRating one) {
			items.add(one);
		}

		boolean canBeSurprisingWithBestGreater(int withsum, int p) {
			for (SurprisingRating rating : items) {
				if (rating.sum == withsum) {
					return (rating.best >= p);
				}
			}

			return false;
		}
	}

	// x x+2 x = 3x +2
	// x x+2 x+1 = 3x +3
	// x x+2 x+2 = 3x +4
	static class SurprisingRating {
		int sum = 0;
		int best = 0;

		public SurprisingRating(int sum, int best) {
			this.sum = sum;
			this.best = best;
		}
	}
}
