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 ? " *" : ""));
//    }
    
}

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class Googlers {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = null;
		int caseNumber = 0;
		Googlers a = new Googlers();

		try {
			scanner = new Scanner(new FileInputStream(args[0]));
			while (scanner.hasNextLine()) {

				if (caseNumber == 0) {
					scanner.nextLine();
				} else {
					String pairs = scanner.nextLine();
					String[] numbers = pairs.split(" ");

					System.out.println("Case #" + caseNumber + ": "
							+ a.resolve(numbers));
				}
				caseNumber++;
			}

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} finally {
			scanner.close();
		}

	}

	private Integer resolve(String[] data) {

		int googlersNumber = Integer.parseInt(data[0]);
		int surprices = Integer.parseInt(data[1]);
		int p = Integer.parseInt(data[2]);
		int total = 0;

		ArrayList<Integer> googlers = new ArrayList<Integer>();
		for (int i = 0; i < googlersNumber; i++) {
			googlers.add(Integer.parseInt(data[3 + i]));
		}

		// create the triadas

		ArrayList<Integer[]> scores = createTriada(googlers);

		if (surprices > 0) {
			// Count number surpricing
			Integer totalSuprising = countNumberSurprising(scores);

			if (totalSuprising == surprices) {
				// Count p
				total = countP(p, scores);

			} else {
				// Create missing surprises
				scores = createMissingSurprices(surprices - totalSuprising, p,
						scores, false);

				Integer totalSuprisingB = countNumberSurprising(scores);

				if (totalSuprisingB != surprices) {
					scores = createMissingSurprices(surprices - totalSuprising,
							p, scores, true);
				}

				// check p
				total = countP(p, scores);
			}
		} else {
			total = countP(p, scores);
		}

		return total;
	}

	private ArrayList<Integer[]> createTriada(ArrayList<Integer> g) {

		ArrayList<Integer[]> scores = new ArrayList<Integer[]>();

		for (Integer number : g) {
			Integer[] score = new Integer[3];

			for (int i = 3; i > 0; i--) {

				float resultPrecise = number / i;
				int resultInteger = number / i;
				int calification = 0;
				if (resultPrecise > resultInteger) {
					calification = resultInteger + 1;
				} else {
					calification = resultInteger;
				}
				score[i - 1] = calification;
				number = number - calification;
			}
		
			scores.add(score);
		}

		return scores;
	}

	private Boolean checkSurprising(Integer[] scores) {

		Boolean found = false;

		int a = scores[0] - scores[1];
		int b = scores[0] - scores[2];
		int c = scores[1] - scores[2];

		if (a == 2 || b == 2 || c == 2) {
			found = true;
		}

		return found;
	}

	private int countNumberSurprising(ArrayList<Integer[]> c) {

		Boolean found = false;
		int surpriseN = 0;

		for (Integer[] integers : c) {

			if (checkSurprising(integers)) {
				surpriseN++;
			}
		}

		return surpriseN;

	}

	private ArrayList<Integer[]> createMissingSurprices(int missing, int p,
			ArrayList<Integer[]> s, Boolean forced) {

		for (int i = 0; i < s.size(); i++) {

			if (missing > 0) {

				if (!checkP(p, s.get(i)) || forced) {

					if (s.get(i)[1] > 0) {

						if ((s.get(i)[0] < p && s.get(i)[0] + 1 >= p) || forced) {
							
							Integer[] newTripleta = (Integer[])s.get(i).clone();
							newTripleta[0] = newTripleta[0]+1;
							newTripleta[1] = newTripleta[1]-1;

							if (validTripleta(newTripleta)) {
								s.set(i, newTripleta);
								missing--;
							}
						}
					}

				}
			}
		}
		return s;
	}

	private Boolean validTripleta(Integer[] scores) {
		Boolean found = true;

		int a = scores[0] - scores[1];
		int b = scores[0] - scores[2];
		int c = scores[1] - scores[2];

		if (a > 2 || b > 2 || c > 2) {
			found = false;
		}
		return found;
	}

	private Boolean checkP(int p, Integer[] scores) {

		Boolean found = false;

		for (Integer integer : scores) {
			if (integer >= p) {
				found = true;
				break;
			}
		}

		return found;
	}

	private Integer countP(int p, ArrayList<Integer[]> scores) {

		Integer total = 0;

		for (Integer[] integer : scores) {
			for (Integer integer2 : integer) {
				if (integer2 >= p) {
					total++;
					break;
				}
			}
		}

		return total;
	}

}
