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.File;
import java.io.FileWriter;
import java.util.*;

/**
 * Author: Andriy Gusyev
 * Date: 14.04.12
 */
public class Task3 {

    private static class Case {

        private int googlers;

        private int surprising;

        private int minScore;

        private int[] totalScores;

        @Override
        public String toString() {
            return "Case{" +
                    "googlers=" + googlers +
                    ", surprising=" + surprising +
                    ", minScore=" + minScore +
                    ", totalScores=" + Arrays.toString(totalScores) +
                    "}\n";
        }
    }

    private static class Dancer {

        private Integer bestSurprisedScore;

        private Integer bestNonSuprisedScore;

        public Dancer(int totalScore) {
            if (totalScore == 0) {
                bestNonSuprisedScore = 0;
                bestSurprisedScore = 0;
                return;
            }
            switch (totalScore % 3) {
                case 0:
                    bestNonSuprisedScore = totalScore / 3;
                    bestSurprisedScore = totalScore / 3 + 1;
                    if (bestSurprisedScore > 10) {
                        bestSurprisedScore = 10;
                    }
                    break;
                case 1:
                    bestNonSuprisedScore = totalScore / 3 + 1;
                    bestSurprisedScore = totalScore / 3 + 1;
                    if (bestSurprisedScore > 10) {
                        bestSurprisedScore = 10;
                    }
                    break;
                case 2:
                    bestNonSuprisedScore = totalScore / 3 + 1;
                    bestSurprisedScore = totalScore / 3 + 2;
                    if (bestSurprisedScore > 10) {
                        bestSurprisedScore = 10;
                    }
            }
        }

        @Override
        public String toString() {
            return "Dancer{" +
                    "bestNonSuprisedScore=" + bestNonSuprisedScore +
                    ", bestSurprisedScore=" + bestSurprisedScore +
                    "}\n";
        }

        @Override
        public boolean equals(Object o) {
            return false;
        }
    }

    static private int cases;

    static private Case[] objs;

    static private int[] results;

    private static void readInput(String s, int index) {
        s = s.trim();
        String[] arr = s.split(" ");
        Case cas = new Case();
        cas.googlers = Integer.parseInt(arr[0]);
        cas.surprising = Integer.parseInt(arr[1]);
        cas.minScore = Integer.parseInt(arr[2]);
        cas.totalScores = new int[cas.googlers];
        for (int i = 0; i < cas.googlers; i++) {
            cas.totalScores[i] = Integer.parseInt(arr[3 + i]);
        }
        objs[index] = cas;
    }

    public static void main(String args[]) throws Exception {

        Scanner sc = new Scanner(new File("d:/codejam/3/large"), "UTF-8");
        cases = Integer.parseInt(sc.nextLine());
        objs = new Case[cases];
        results = new int[cases];
        for (int i = 0; i < cases; i++) {
            readInput(sc.nextLine(), i);
        }

        for (int i = 0; i < cases; i++) {
            results[i] = proceedCase(objs[i]);
        }
        System.out.println(Arrays.toString(results));
        FileWriter fw = new FileWriter(new File("d:/codejam/3/large_out"));
        int k = 0;
        for (int i : results) {
            k++;
            fw.write(String.format("Case #%s: %s\n", String.valueOf(k), String.valueOf(i)));
        }
        fw.close();
    }

    private static int proceedCase(Case cas) {
        int result = 0;
        List<Dancer> dancers = new ArrayList<Dancer>();
        for (int i = 0; i < cas.googlers; i++) {
            dancers.add(new Dancer(cas.totalScores[i]));
        }
        Collections.sort(dancers, new Comparator<Dancer>() {
            public int compare(Dancer o1, Dancer o2) {
                if (o1.bestNonSuprisedScore == o2.bestNonSuprisedScore) {
                    return -o1.bestSurprisedScore.compareTo(o2.bestSurprisedScore);
                }
                return -o1.bestNonSuprisedScore.compareTo(o2.bestNonSuprisedScore);
            }
        });
        System.out.println(dancers);
        int surprisedUsed = 0;
        for (Dancer dancer : dancers) {
            if (dancer.bestNonSuprisedScore >= cas.minScore) {
                result++;
                continue;
            } else if (dancer.bestSurprisedScore >= cas.minScore && cas.surprising > surprisedUsed) {
                result++;
                surprisedUsed++;
                continue;
            }
        }
        return result;
    }
}
