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 codejam;
import java.util.ArrayList;
import java.util.Collections;
public class DWG {
	int findCount(int N,int S,int p,ArrayList<Integer>arr){
		int count = 0;
		Collections.sort(arr);
		int i = 0;
		while( S != 0 && i<arr.size()){
			int val = 0;
			
			val = arr.get(i);			
			if( (val -3)%3 == 0 && (val-3)>=0){
				int q = (val -3 ) / 3;
				if( (q+2) >=p){
					count++;
					arr.set(i, -1);
					S--;
				}
			}
			else if( (val -2)%3 == 0 &&(val-2)>=0){
				int q = (val -2 ) / 3;
				if( (q+2) >=p){
					count++;
					arr.set(i, -1);
					S--;
				}
			}
			else if( (val -4)%3 == 0 && (val -4)>=0){
				int q = (val -4 ) / 3;
				if( (q+2) >=p){
					count++;
					arr.set(i, -1);
					S--;
				}
			}
			i++;
		}
		for(i = 0; i<N;i++){
			int val = arr.get(i);
			if( val >=0){
				if( (val)%3 == 0){
					int q = (val ) / 3;
					if( (q) >=p){
						count++;
						arr.set(i, -1);						
					}
				}
				else if( (val - 2)%3 == 0 && (val - 2)>=0){
					int q = (val -2 ) / 3;
					if( (q+1) >=p){
						count++;
						arr.set(i, -1);
						
					}
				}
				else if( (val-1)%3 == 0 && (val - 1)>=0){
					int q = (val -1 ) / 3;
					if( (q+1) >=p){
						count++;
						arr.set(i, -1);
						
					}
				}
				
			}
		}	
		
		return count;
	}
	public static void main(String []args){
		DWG d = new DWG();
		
		FileRead fr = new FileRead("B-small-attempt1.in");
		FileWrite fw = new FileWrite("B-small-ouput1.txt");
		
		int num = 0;
		
		int t = fr.readNextInt();
		for(int i = 0; i< t ; i++){
			int arr[] = fr.readNextIntArray();
			
			ArrayList<Integer> a = new ArrayList<Integer>();
			int j = 0;
			for(;j<arr[0];j++){
				a.add(arr[j+3]);
			}
			
			num = d.findCount(arr[0], arr[1], arr[2], a);
			fw.writeLine("Case #"+(i+1)+": "+num);
			
		}
		fw.close();
		fr.close();

	}
}
