package CodeJam.c2012.clasificacion;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * Problem
 *
 * You're watching a show where Googlers (employees of Google) dance, and then
 * each dancer is given a triplet of scores by three judges. Each triplet of
 * scores consists of three integer scores from 0 to 10 inclusive. The judges
 * have very similar standards, so it's surprising if a triplet of scores
 * contains two scores that are 2 apart. No triplet of scores contains scores
 * that are more than 2 apart.
 *
 * For example: (8, 8, 8) and (7, 8, 7) are not surprising. (6, 7, 8) and (6, 8,
 * 8) are surprising. (7, 6, 9) will never happen.
 *
 * The total points for a Googler is the sum of the three scores in that
 * Googler's triplet of scores. The best result for a Googler is the maximum of
 * the three scores in that Googler's triplet of scores. Given the total points
 * for each Googler, as well as the number of surprising triplets of scores,
 * what is the maximum number of Googlers that could have had a best result of
 * at least p?
 *
 * For example, suppose there were 6 Googlers, and they had the following total
 * points: 29, 20, 8, 18, 18, 21. You remember that there were 2 surprising
 * triplets of scores, and you want to know how many Googlers could have gotten
 * a best result of 8 or better.
 *
 * With those total points, and knowing that two of the triplets were
 * surprising, the triplets of scores could have been:
 *
 * 10 9 10 6 6 8 (*) 2 3 3 6 6 6 6 6 6 6 7 8 (*)
 *
 * The cases marked with a (*) are the surprising cases. This gives us 3
 * Googlers who got at least one score of 8 or better. There's no series of
 * triplets of scores that would give us a higher number than 3, so the answer
 * is 3.
 *
 * Input
 *
 * The first line of the input gives the number of test cases, T. T test cases
 * follow. Each test case consists of a single line containing integers
 * separated by single spaces. The first integer will be N, the number of
 * Googlers, and the second integer will be S, the number of surprising triplets
 * of scores. The third integer will be p, as described above. Next will be N
 * integers ti: the total points of the Googlers.
 *
 * Output
 *
 * For each test case, output one line containing "Case #x: y", where x is the
 * case number (starting from 1) and y is the maximum number of Googlers who
 * could have had a best result of greater than or equal to p.
 *
 * Limits
 *
 * 1 â¤ T â¤ 100. 0 â¤ S â¤ N. 0 â¤ p â¤ 10. 0 â¤ ti â¤ 30. At least S of the ti values
 * will be between 2 and 28, inclusive.
 *
 * Small dataset
 *
 * 1 â¤ N â¤ 3.
 *
 * Large dataset
 *
 * 1 â¤ N â¤ 100.
 *
 * Sample
 *
 * Input Output 4 Case #1: 3 3 1 5 15 13 11 Case #2: 2 3 0 8 23 22 21 Case #3: 1
 * 2 1 1 8 0 Case #4: 3 6 2 8 29 20 8 18 18 21
 *
 * @author Leandro Baena Torres
 */
public class B {

    public static void main(String[] args) throws FileNotFoundException, IOException {
        BufferedReader br = new BufferedReader(new FileReader("B.in"));
        String linea;
        int numCasos, N, S, p, t[], y, minSurprise, minNoSurprise;

        linea = br.readLine();
        numCasos = Integer.parseInt(linea);
        for (int i = 0; i < numCasos; i++) {
            linea = br.readLine();
            String[] aux = linea.split(" ");
            N = Integer.parseInt(aux[0]);
            S = Integer.parseInt(aux[1]);
            p = Integer.parseInt(aux[2]);
            t = new int[N];
            y = 0;
            minSurprise = p + ((p - 2) >= 0 ? (p - 2) : 0) + ((p - 2) >= 0 ? (p - 2) : 0);
            minNoSurprise = p + ((p - 1) >= 0 ? (p - 1) : 0) + ((p - 1) >= 0 ? (p - 1) : 0);
            for (int j = 0; j < N; j++) {
                t[j] = Integer.parseInt(aux[3 + j]);
                if (t[j] >= minNoSurprise) {
                    y++;
                } else {
                    if (t[j] >= minSurprise) {
                        if (S > 0) {
                            y++;
                            S--;
                        }
                    }
                }
            }

            System.out.println("Case #" + (i + 1) + ": " + y);
        }
    }
}

import java.io.*;
import java.util.*;

public class Main {

	public static Map<Integer, Integer> mapMax=Collections.synchronizedMap( new HashMap<Integer, Integer>());
	public static Map<Integer, Integer> mapSurprisingMax=Collections.synchronizedMap( new HashMap<Integer, Integer>());
	
	/**
	 * */
	public static double getFactor( int n){
		double nFactor=( double) 1;
		for( int i=1; i<=n; i++)
			nFactor*=i; 
		return nFactor; }
	
	/**
	 * */
	public static double getCombinations( int nData, int nItems){
		return getFactor( nData)/ ( getFactor( nData- nItems)* getFactor( nItems)); }
	
	/**
	 * */
	/**@class Combination
	 * */
	public class Combination{
		public Integer lastElement=0;
		public Set<Integer> setItems=Collections.synchronizedSet( new HashSet<Integer>());
		/***/
		public Combination(){}
		public Combination( Combination src){
			this.lastElement=src.lastElement;
			this.setItems.addAll( src.setItems); }
		public void addItem( Integer item){
			this.lastElement=item;  
			this.setItems.add( this.lastElement); }}
	
	/**@class Combinator
	 * */
	public class Combinator{
		
		public Integer[] rItems;
		
		/**@param nItems
		 * */
		public Combinator( int nItems){
			this.rItems=new Integer[ nItems];
			for( int i=0; i!=this.rItems.length; i++) 
				this.rItems[ i]=i; }
		
		/**@param nSubitems
		 * */
		public double countCombinations( int nSubitems){
			return Main.getCombinations( this.rItems.length, nSubitems);  }

		/**@
		 * */
		private Set<Combination> _getCombinations( Set<Combination> srcCombinations, int nSubitems){
			Set<Combination> setCombinations=Collections.synchronizedSet( new HashSet<Combination>());
			Iterator<Combination> iter=srcCombinations.iterator();
			while( iter.hasNext()){
				Combination srcCombination=iter.next(); 
				if( srcCombination.setItems.size()==nSubitems){
					setCombinations.add( srcCombination); 
				}else{					
					Set<Combination> setSubitems=Collections.synchronizedSet( new HashSet<Combination>());
					for( int i=0; i!=this.rItems.length; i++){
						Combination combination=new Combination( srcCombination);
						if( this.rItems[ i]> combination.lastElement){
							combination.addItem( this.rItems[ i]);
							setSubitems.add( combination); }}					
					setCombinations.addAll( this._getCombinations( setSubitems, nSubitems)); 	}}
			return setCombinations; }
				
		/**@param nSubitems
		 * */
		public Set<Combination> getCombinations( int nSubitems){
			Set<Combination> setCombinations=Collections.synchronizedSet( new HashSet<Combination>());
			double nCombinations=this.countCombinations( nSubitems); 
			if( nCombinations>0){				
				for( int i=0; i!=this.rItems.length; i++){
					Combination combination=new Combination();
					combination.addItem( this.rItems[ i]); 
					setCombinations.add( combination); }
				return this._getCombinations( setCombinations, nSubitems); }
			return setCombinations; }}
	
	/**
	 * */
	public class TestCase{
		
		public Integer id, n, s, p; 
		public Integer iResult=0;
		public Integer[] rPoints; 
		/***/
		public TestCase( Integer id, Integer n, Integer s, Integer p, Integer[] rPoints){
			this.id=id; 
			this.n=n; 
			this.s=s; 
			this.p=p; 
			this.rPoints=Arrays.copyOf( rPoints, rPoints.length); }
		
		/***/
		public void doSolution(){
			this.iResult=0;
			if( this.s==0){
				for( int i=0; i!=this.rPoints.length; i++){
					if( Main.mapMax.get( this.rPoints[ i])>=this.p)
						this.iResult++; }				
			}else{
				/***/
				Combinator combinator=new Combinator( this.n); 
				Set<Combination> setCombinations=combinator.getCombinations( this.s);
				Iterator<Combination> iterCombination=setCombinations.iterator();
				while( iterCombination.hasNext()){
					Combination combination=iterCombination.next();
					this.iResult=Math.max( this.iResult, 
							this.doCombination( combination)); }}}
		
		public Integer doCombination( Combination combination){
			Integer iResult=0;
			for( int i=0; i!=this.rPoints.length; i++){
				Integer max=( combination.setItems.contains( i))? Main.mapSurprisingMax.get( this.rPoints[ i]): 
					Main.mapMax.get( this.rPoints[ i]);
				if( max>=this.p)
					iResult++; }
			return iResult; }
	}	
	public TestCase createTestCase( Integer id, Integer n, Integer s, Integer p, Integer[] rPoints){
		return new TestCase( id, n, s, p, rPoints); } 
		
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		try {
			
			Main m=new Main();
			LineNumberReader reader=new LineNumberReader( new FileReader( new File( args[ 0].trim())));
			PrintWriter printer=new PrintWriter( new FileWriter( args[ 1].trim()));
			
				
			/** ScoreMaps */
			for( int i0=0; i0<=10; i0++){
				for( int i1=0; i1<=10; i1++){
					for( int i2=0; i2<=10; i2++){
						Integer maxScore=Math.max( i0, Math.max( i1, i2)); 
						if( ( Math.abs( i0- i1)<= 2) && ( Math.abs( i0- i2)<= 2) && ( Math.abs( i1- i2)<= 2)){
							Integer nSum=i0+ i1+ i2;
							// Not surprising score. 
							if( !(( Math.abs( i0- i1)==2) ||  ( Math.abs( i0- i2)==2) || ( Math.abs( i1- i2)==2))){
								if( !Main.mapMax.containsKey( nSum)){
									Main.mapMax.put( nSum, maxScore); }					
								Main.mapMax.put( nSum, Math.max( Main.mapMax.get( nSum), maxScore)); }
							// Surprising Score. 
							if( !Main.mapSurprisingMax.containsKey( nSum)){
								Main.mapSurprisingMax.put( nSum, maxScore); }					
							Main.mapSurprisingMax.put( nSum, Math.max( Main.mapSurprisingMax.get( nSum), maxScore)); }}}}

			/***/
			int nTestCases=Integer.valueOf( reader.readLine().trim());
			for( int n=0; n!=nTestCases; n++){
				String str[]=reader.readLine().split( " ");
				Integer[] rPoints=new Integer[ str.length- 3];
				for( int i=3; i!=str.length; i++)
					rPoints[ i- 3]=Integer.valueOf( str[ i].trim()); 
				TestCase testCase=m.createTestCase( n+ 1, 
						Integer.valueOf( str[ 0].trim()), 
						Integer.valueOf( str[ 1].trim()), Integer.valueOf( str[ 2].trim()), rPoints);				
				testCase.doSolution();				
				printer.println( "Case #"+ testCase.id+": "+ testCase.iResult);
				System.out.println( "Case #"+ testCase.id+": "+ testCase.iResult); }
			
			printer.close();
			
		} catch (FileNotFoundException e) {
			
			e.printStackTrace(); } 
		catch (IOException e) {
			e.printStackTrace(); }}}
