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 mgg.problems;

import java.util.ArrayList;
import java.util.List;

import mgg.utils.CombinatoryUtils;
import mgg.utils.FileUtil;
import mgg.utils.StringUtils;
import mgg.utils.Triplet;

/**
 * @author manolo
 * @date 14/04/12
 */
public class ProblemB {

	public final static String EXAMPLE_IN = "B-example.in";
	public final static String EXAMPLE_OUT = "B-example.out";

	public final static String B_SMALL_IN = "B-small-attempt0.in";
	public final static String B_SMALL_OUT = "B-small-attempt0.out";

	public final static String B_LARGE_IN = "B-large.in";
	public final static String B_LARGE_OUT = "B-large.out";

	public final static String delim = " ";

	public static String solve(FileUtil util) {

		String line = util.getLine();
		List<Integer> listOfArgs = StringUtils.stringWithIntegersToList(line, delim);
		//System.out.println("\tArgs = " + listOfArgs);

		int googlers = listOfArgs.get(0);
		System.out.println("\tGooglers = " + googlers);

		int surprisingScores = listOfArgs.get(1);
		System.out.println("\tSurprising scores = " + surprisingScores);

		int leastScore = listOfArgs.get(2);
		System.out.println("\tMinimum = " + leastScore);

		List<Integer> listOfScores = listOfArgs.subList(3, listOfArgs.size());
		System.out.println("\tScores = " + listOfScores);

		List<Triplet> listOfTriplets, newListOfTriplets = new ArrayList<Triplet>();
		int surprisingScoresLeft = surprisingScores;
//		int [] withTriplets = new int[3];
//		withTriplets[0] = 0;
//		withTriplets[1] = 0;
//		withTriplets[2] = 0;
		
		int greatGooglers = 0;
		for(int score : listOfScores){

			listOfTriplets = CombinatoryUtils.possibleTriplets(score);
			//System.out.println("\tPossible triplets: " + listOfTriplets);

			newListOfTriplets = new ArrayList<Triplet>();
			for(Triplet t : listOfTriplets){
				if (t.max() >= leastScore){
					newListOfTriplets.add(t);
				}
			}
			System.out.println("\tNew possible triplets: " + newListOfTriplets);
			
//			withTriplets[newListOfTriplets.size()]++;
			
			if(newListOfTriplets.size() == 2){
				greatGooglers++;
			}
			if(newListOfTriplets.size() == 1){
				if(newListOfTriplets.get(0).isSurprising() && surprisingScoresLeft > 0){
					greatGooglers++;
					surprisingScoresLeft--;
				}
				if(!newListOfTriplets.get(0).isSurprising()){
					greatGooglers++;
				}
			}
			
		}
		
		return "" + greatGooglers;
		
//		System.out.println("\t" + withTriplets[0] + " with 0 triples");
//		System.out.println("\t" + withTriplets[1] + " with 1 triples");
//		System.out.println("\t" + withTriplets[2] + " with 2 triples");
//		
//		if((surprisingScores == 0) && (withTriplets[1] > 0)){
//			return "0";
//		}
//		if(surprisingScores > withTriplets[1]){
//			return "0";
//		}
//		else {
//			return "" + (withTriplets[1] + withTriplets[2]);  
//		}
	}

	private static Triplet takeMax(List<Triplet> listOfTriplets) {

		Triplet max_t = new Triplet(-1, -1, -1); 
		for(Triplet t : listOfTriplets){
			if(!max_t.isSurprising()){
				if(t.isSurprising()){
					max_t = t;
				}
				else if(t.max() > max_t.max()){
					max_t = t;
				}
			}


		}
		return max_t;

	}

}
