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 org.cb.projectb.dancingwiththegooglers;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Contest {
	
	public static void main(String[] args) throws FileNotFoundException {
		File input = new File(System.getProperty("user.dir") + "/" + "resources/projectB/B-large.in");
		Scanner sc = new Scanner(input);

		List<DanceOff> contests = new ArrayList<DanceOff>();
		
		if (sc.hasNext()) {
			Integer.parseInt(sc.nextLine()); // number of cases - ignored
			while (sc.hasNext()) {
				String contestString = sc.nextLine();
				
				StringTokenizer contestTokenizer = new StringTokenizer(contestString);
				
				int contestants = Integer.parseInt(contestTokenizer.nextToken());
				int surprisingTriplets = Integer.parseInt(contestTokenizer.nextToken());
				int scoreWeCareAbout = Integer.parseInt(contestTokenizer.nextToken());
				List<Integer> scores = new ArrayList<Integer>();
				for(int i = 0; i < contestants; i ++) {
					scores.add(Integer.parseInt(contestTokenizer.nextToken()));
				}
				
				contests.add(new DanceOff(contestants, surprisingTriplets, scoreWeCareAbout, scores));
			}
		}
		
		for(int i = 1; i <= contests.size(); i ++) {
			DanceOff danceoff = contests.get(i-1);

			System.out.println("Case #" + i + ": " + danceoff.getNumberAllowedToBeImportant());
		}
	}
	
	private static class DanceOff {
		private final int contestants;
		private final int surprisingTriplets;
		private final int scoreWeCareAbout;
		private final List<Integer> contestantScores;
		private final int numberAllowedToBeImportant;
		
		public DanceOff(int contestants, int surprisingTriplets, int scoreWeCareAbout, List<Integer> contestantScores) {
			this.contestants = contestants;
			this.surprisingTriplets = surprisingTriplets;
			this.scoreWeCareAbout = scoreWeCareAbout;
			this.contestantScores = contestantScores;
			
			this.numberAllowedToBeImportant = fillInDetails();
		}

		private int fillInDetails() {
			int importantScores = 0;
			
			List<Integer[]> allProbableScores = new ArrayList<Integer[]>();
			
			for(Integer score: contestantScores) {
//				System.out.print(score + " - ");
				
				int baseScore = score / 3;
				int remaining = score % 3;
				Integer[] scoresArray = new Integer[]{baseScore, baseScore, baseScore};
				
				for(int i = 0; i < remaining; i++) {
					scoresArray[i] = scoresArray[i] + 1;
				}
				
//				System.out.print("Probable tripplet: [");
//				for(int i = 0; i < scoresArray.length; i++) {
//					System.out.print(scoresArray[i] + " ");
//				}
//				System.out.println("]");
				
				allProbableScores.add(scoresArray);
			}
			
			
			int freebeeImportantScores = 0;
			int ableToBeImportantIfSurprising = 0;
			for (Integer[] scoresList : allProbableScores) {
				// count how many in scores array are already important
				boolean isImportant = false;
				boolean canBeSurprising = false;
				
				for (Integer integer : scoresList) {
					if(integer >= this.scoreWeCareAbout) {
						isImportant = true;
						break;
					}
				}
				if(isImportant) {
					freebeeImportantScores++;
				} else {
					// see how many i can make 'surprising' to then care about
					if(scoresList[0] + 1 >= this.scoreWeCareAbout) {
						if(scoresList[0] == scoresList[1] && scoresList[0] != 0) {
							canBeSurprising = true;
						}
					}
					if(canBeSurprising) {
						ableToBeImportantIfSurprising++;
					}
				}
			}
			

			
			// take min of allowed surprising & how many could be surprised
			int numToMakeSpecial = Math.min(ableToBeImportantIfSurprising, this.surprisingTriplets);
			
			// add min to current important scores
			importantScores = freebeeImportantScores + numToMakeSpecial;
			
//			System.out.println("Freebee important: " + freebeeImportantScores);
//			System.out.println("Can be Made Important with surprising Score: " + ableToBeImportantIfSurprising);
//			System.out.println("Num Of Scores we are making surprising: " + numToMakeSpecial);
//			System.out.println("Max Special Scores: " + importantScores);
//			System.out.println();
			
			return importantScores;
		}
		
		public int getNumberAllowedToBeImportant() {
			return numberAllowedToBeImportant;
		}

		@Override
		public String toString() {
			return "DanceOff [contestants = " + contestants
					+ ", surprisingTriplets = " + surprisingTriplets
					+ ", scoreWeCareAbout = " + scoreWeCareAbout
					+ ", contestantScores = " + contestantScores + "]";
		}
	}

}
