package com.example;

import java.io.IOException;
import java.util.List;

public class ProblemB {
    
    enum Result {
	INSUFFICIENT,
	SUFFICIENT,
	SUFFICIENT_WHEN_SURPRISING
    }

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

	List<String> lines = FileUtil.getLines("/B-large.in");
	
	int cases = Integer.valueOf(lines.get(0));
	
	for(int c=0; c<cases; c++) {
	    String[] tokens = lines.get(c+1).split(" ");
	    
	    int n = Integer.valueOf(tokens[0]); // N = number of Googlers
	    int s = Integer.valueOf(tokens[1]); // S = number of surprising triplets
	    int p = Integer.valueOf(tokens[2]); // P = __at least__ a score of P
	    
	    int sumSufficient = 0;
	    int sumSufficientSurprising = 0;
	    
	    for(int i=0; i<n; i++) {
		int points = Integer.valueOf(tokens[3+i]);
		
		switch(test(points, p)) {
		case SUFFICIENT:
		    sumSufficient++;
		    break;
		    
		case SUFFICIENT_WHEN_SURPRISING:
		    sumSufficientSurprising++;
		    break;
		}
		
//		uSystem.out.println("points "+ points +" ? "+ p +" => "+ result);
	    }
	    
	    System.out.println("Case #"+ (c+1) +": "+ (sumSufficient + Math.min(s, sumSufficientSurprising)));
	    
//	    System.out.println();
//	    System.out.println("N="+ n +", S="+ s +", P="+ p);
//	    System.out.println();
	}
    }

    private static Result test(int n, int p) {
	int fac = n / 3;
	int rem = n % 3;
	
	if(rem == 0) {
	    
//	    int triplet0[] = { fac, fac, fac };
//	    print(n, triplet0);
	    
	    if(fac >= p) {
		return Result.SUFFICIENT;
	    }
	    
	    if(fac > 0 && fac < 10) {
		
		if(fac+1 >= p) {
		    return Result.SUFFICIENT_WHEN_SURPRISING;
		}
		
//		int triplet1[] = { fac+1, fac, fac-1 }; // surprising 
//		print(n, triplet1);
	    }
	    
	    
	} else if(rem == 1) {
	    
//	    int triplet0[] = { fac+1, fac, fac };
//	    print(n, triplet0);
	    
	    if(fac+1 >= p) {
		return Result.SUFFICIENT;
	    }
	    
//	    if(fac > 0 && fac < 10) {
//		int triplet1[] = { fac+1, fac+1, fac-1 };
//		print(n, triplet1);
//	    }
	    
	} else if(rem == 2) {
	    
//	    int triplet0[] = { fac+1, fac+1, fac };
//	    print(n, triplet0);
	    
	    if(fac+1 >= p) {
		return Result.SUFFICIENT;
	    }
	    
	    if(fac < 9) {
//		int triplet1[] = { fac+2, fac, fac }; // surprising
//		print(n, triplet1);

		if(fac+2 >= p) {
		    return Result.SUFFICIENT_WHEN_SURPRISING;
		}
	    }
	    
	} else {
	    throw new RuntimeException("error");
	}
	
	return Result.INSUFFICIENT;
//	System.out.println();
//	System.out.println(n +" => "+ div3 +" ("+ rem +")");
    }
    
//    private static void print(int n, int[] triplet) {
//	System.out.println("n="+ n +" ("+ (n/3) +","+ (n%3) +") => ["+ triplet[0] +","+ triplet[1] +","+ triplet[2] +"]" + (triplet[0]-triplet[2] > 1 ? " *" : ""));
//    }
    
}

package Problem2;

import java.util.ArrayList;

public class DancingGooglers {
	
	//3 1 5 15 13 11
	
	// tab[0] = numbe of dancers
	// tab[1] = number of *
	// tab[2] = threshold p

	public static int[] Assign_Stars(int allowed_stars, int[] sumratingtab, int threshold){
		
		int a= allowed_stars;
		int n=sumratingtab.length;
		int[] maxrates= new int[n];
		int i;

			if (a>0){
				for (i=0;i<n;i++){
					if ((sumratingtab[i]>0) && (sumratingtab[i] % 3 == 2) && (  ((sumratingtab[i]-2)/3 + 1)<threshold) &&  (  ((sumratingtab[i]-2)/3 +2) >= threshold)){
					
				//	if ((sumratingtab[i]>=0) && (sumratingtab[i] % 3 == 2)){
						if (a>0){
							maxrates[i]= (sumratingtab[i]-2)/3 + 2;
							System.out.println("etoile gaspillee pour :" + maxrates[i] + " reste :" +(a-1) );
							sumratingtab[i]=-1;
							a--;
						}
					}	
				}
			}

			if (a>0){
				for (i=0;i<n;i++){					
					if ((sumratingtab[i]>0) && (sumratingtab[i] % 3 == 0) && (((sumratingtab[i])/3 ) <threshold) && (((sumratingtab[i])/3+1 ) >= threshold) ){
				//	if ((sumratingtab[i]>=0) && (sumratingtab[i] % 3 == 0) ){
						if (a>0){

							maxrates[i]= sumratingtab[i]/3 + 1 ;
							System.out.println("etoile gaspillee pour :" + maxrates[i] + " reste :" +a);
							sumratingtab[i]=-1;
							a--;
						}
					}	
				}
			}
			
//			if (a>0){
//				for (i=0;i<n;i++){
//					if ( (sumratingtab[i]>0) && (sumratingtab[i] % 3 == 0) ){ 
//						if (a>0){
//
//							maxrates[i]= ((sumratingtab[i]/3)) + 1 ;
//							sumratingtab[i]=-1;
//							a--;
//						}
//						
//					}	
////					if ( (sumratingtab[i]>0) && (sumratingtab[i] % 3 == 1) ){ 
////						if (a>0){
////
////							maxrates[i]= (((sumratingtab[i]-1)/3)) + 1 ;
////							sumratingtab[i]=-1;
////							a--;
////						}	
////					}
//					if ( (sumratingtab[i]>0) && (sumratingtab[i] % 3 == 2) ){ 
//						if (a>0){
//
//							maxrates[i]= (((sumratingtab[i]-2)/3)) + 2 ;
//							sumratingtab[i]=-1;
//							a--;
//						}	
//					}
//				}
//				
//			}
			

				for (i=0;i<n;i++){
					if ( (sumratingtab[i]>0) && (sumratingtab[i] % 3 == 0) ){ 
		
							maxrates[i]= ((sumratingtab[i]/3))  ;
							sumratingtab[i]=-1;
						
					}	
					if ( (sumratingtab[i]>0) && (sumratingtab[i] % 3 == 1) ){ 

							maxrates[i]= (((sumratingtab[i]-1)/3)) + 1 ;
							sumratingtab[i]=-1;
					}
					if ( (sumratingtab[i]>0) && (sumratingtab[i] % 3 == 2) ){ 
							maxrates[i]= (((sumratingtab[i]-2)/3)) + 1 ;
							sumratingtab[i]=-1;
							
					}
				}
		return maxrates;
	}
	
	public static int countmorethanp(int[] maxrates ,int p){
		int n=maxrates.length;
		int i;
		int count=0;
		for (i=0;i<n;i++){
			if (maxrates[i]>=p){
				count++;
			}
		}
		return count;
	}
	
//	public static void main(String[] args){
//		
//		int[] tab = {8,0};
//		// 2 1 1 8 0
//	//	6  8 
//		int[] tab2 = Assign_Stars(1, tab, 1);
//		int i=0;
//		for (i=0;i<tab2.length;i++){
//			System.out.println("tab2 : "+tab2[i]);
//		}
//		System.out.println(countmorethanp(tab2, 1));
//	}
	
	public static int result(int allowedstars , int[] tabsum,int threshold ){
	
	int[] tab2 = Assign_Stars(allowedstars, tabsum, threshold);
	
	return countmorethanp(tab2, threshold);
	}
	
	public static int StringtoResults(String s1){
		String[] arrs = s1.split(" ");
		int i=1,n=arrs.length;
		int allowedstars = Integer.parseInt(arrs[1]);
		int threshold = Integer.parseInt(arrs[2]);
		int[] arr = new int[n-3];
		for (i=3;i<n;i++){
			arr[i-3]= Integer.parseInt(arrs[i]);
		}
		return result(allowedstars,arr,threshold);
	}
	
	public static int[] Count_List(ArrayList<String> ArS){
		
		int[] Ars_res = new int[ArS.size()]; 
		int i=0;
		int n =ArS.size();
		
		for(i=0;i<n;i++){
			Ars_res[i]=StringtoResults(ArS.get(i));
		}
		return Ars_res;
		
	}
	
}
