import java.io.*;
import java.math.*;
import java.util.*;
import java.text.*;

public class b {
    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedInputStream(System.in));

        int T = sc.nextInt();

        for (int casenumber = 1; casenumber <= T; ++casenumber) {

            int n = sc.nextInt();
            int s = sc.nextInt();
            int p = sc.nextInt();

            int[] ts = new int[n];
            for (int i = 0; i < n; ++i)
                ts[i] = sc.nextInt();

            int thresh1 = (p == 1 ? 1 : (3 * p - 4));
            int thresh2 = (3 * p - 2);

            int count1 = 0, count2 = 0;

            for (int i = 0; i < n; ++i) {
                if (ts[i] >= thresh2) {
                    ++count2;
                    continue;
                }
                if (ts[i] >= thresh1) {
                    ++count1;
                }
            }

            if (count1 > s) {
                count1 = s;
            }

            System.out.format("Case #%d: %d%n", casenumber, count1 + count2);
        }
    }
}

package tr0llhoehle.cakemix.googleCodejam;

import tr0llhoehle.cakemix.utility.googleCodeJam.Solver;

public class DWGSolver implements Solver<DWGProblem> {

	@Override
	public String solve(DWGProblem p) {
		int numberOfBestResult = 0;
		int surprising = 0;

		/*
		 * for (int sum : p.getDancerSums()) { int[] triplet = new int[3];
		 * boolean done = false; int remainder = sum % 3;
		 * 
		 * for (int i : triplet) { i = sum / 3;
		 * 
		 * if (remainder > 0) { i++; remainder--; } // not-surprising triplets
		 * generated.
		 * 
		 * if (i >= p.getBorder()) { numberOfBestResult++; done = true; break; }
		 * }
		 * 
		 * if (!done && sum > 1 && surprising < p.getNumberOfSuprisingTriplets()
		 * && triplet[0] + 1 >= p.getBorder()) { numberOfBestResult++;
		 * surprising++;
		 * 
		 * } }
		 */

		for (int sum : p.getDancerSums()) {
			int avg = sum / 3;
			int remainder = sum % 3;

			if (sum == 0) {
				if (p.getBorder() <= 0) {
					numberOfBestResult++;
				}
			} else if (sum == 1) {
				if (p.getBorder() <= 1) {
					numberOfBestResult++;
				}
			} else { // sum >= 2
				switch (remainder) {
				case 0:
					if (avg >= p.getBorder()) {
						numberOfBestResult++;
					} else if (surprising < p.getNumberOfSuprisingTriplets()
							&& avg + 1 >= p.getBorder()) {
						numberOfBestResult++;
						surprising++;
					}
					break;
				case 1:
					if (avg + 1 >= p.getBorder()) {
						numberOfBestResult++;
					}
					break;
				case 2:
					if (avg + 1 >= p.getBorder()) {
						numberOfBestResult++;
					} else if (surprising < p.getNumberOfSuprisingTriplets()
							&& avg + 2 >= p.getBorder()) {
						numberOfBestResult++;
						surprising++;
					}
					break;
				}
			}
		}

		return numberOfBestResult + "";
	}
}
