package codejam;

import fixjava.Pair;

public class Utils {

	public static long minLong(long firstVal, long... otherVals) {
		long minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	public static int minInt(int firstVal, int... otherVals) {
		int minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	public static float minFloat(float firstVal, float... otherVals) {
		float minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	/**
	 * ArgMin returned as a Pair<Integer, Integer>(index, value). Array must
	 * have at least one value.
	 */
	public static Pair<Integer, Integer> argMin(int[] arr) {
		int min = arr[0];
		int argMin = 0;
		for (int i = 1; i < arr.length; i++) {
			if (arr[i] < min) {
				min = arr[i];
				argMin = i;
			}
		}
		return new Pair<Integer, Integer>(argMin, min);
	}

	/**
	 * ArgMax returned as a Pair<Integer, Integer>(index, value). Array must
	 * have at least one value.
	 */
	public static Pair<Integer, Integer> argMax(int[] arr) {
		int max = arr[0];
		int argMax = 0;
		for (int i = 1; i < arr.length; i++) {
			if (arr[i] > max) {
				max = arr[i];
				argMax = i;
			}
		}
		return new Pair<Integer, Integer>(argMax, max);
	}

}

package org.tritree_tritree;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

public class ProblemBLarge {

	public static void main(String[] args) throws IOException {
		File source = new File("B-large.in");
		Scanner scan = new Scanner(source);

		int t = scan.nextInt();
		scan.nextLine();
		List<String> resultList = new ArrayList<String>();
		for (int i = 1; i < t + 1; i++) {
			int n = scan.nextInt();
			int s = scan.nextInt();
			int p = scan.nextInt();
			int[] pointArray = new int[n];
			for (int j = 0; j < n; j++) {
				pointArray[j] = scan.nextInt();
			}
			String result = "Case #" + i + ": " + resolve(s, p, pointArray);
			resultList.add(result);
		}

		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_hhmmss");
		File resultFile = new File("B-large-" + dateFormat.format(new Date()) + ".out");
		FileOutputStream fileOutputStream = new FileOutputStream(resultFile);

		for (String result: resultList) {
			result = result + "\n";
			fileOutputStream.write(result.getBytes());
		}
		fileOutputStream.flush();
		fileOutputStream.close();
	}

	private static int resolve(int s, int p, int[] pointArray) {
		int cnt = 0;
		int remainScnt = s;
		for (int i = 0; i < pointArray.length; i++) {
			int target = pointArray[i];
			if (p*3 -2  <= target) {
				cnt++;
			} else if (target == 0) {
				continue;
			} else if (0 < remainScnt) {
				if (p*3 -4  <= target) {
					cnt++;
					remainScnt--;
				}
			}
		}
		return cnt;
	}

}
