import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;


public class GooglersDancer {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		InputStreamReader converter = new InputStreamReader(System.in);
		BufferedReader in = new BufferedReader(converter);
		if (in == null) {
		      return;
		    }
		String numTest = in.readLine();
		int maxCases = Integer.valueOf(numTest);
		for(int i=1;i<= maxCases;i++){
			String linea = in.readLine();
			String[] datos = linea.split(" ");
			Integer googlers = Integer.valueOf(datos[0]);
			Integer sospechosos = Integer.valueOf(datos[1]);
			Integer p = Integer.valueOf(datos[2]);
			Integer puntuacion;
			Integer personas = 0;
			ArrayList<Integer> puntuaciones = new ArrayList<Integer>();
			for(int j=0;j<googlers;j++){
				puntuacion = Integer.valueOf(datos[3+j]);
				puntuaciones.add(puntuacion);
			}
			Integer[] pOrdenado = null;
			pOrdenado = (Integer[]) puntuaciones.toArray(new Integer[puntuaciones.size()]);
			Arrays.sort(pOrdenado);
			int j;
			for(j=pOrdenado.length-1;j>=0;j--){
				if(pOrdenado[j] >= p*3-2){
					personas += 1;
				}else{
					break;
				}
			}
			int posibles = j+1-sospechosos;
			for(;j>=posibles && j>= 0;j--){
				if(pOrdenado[j] >= p*3-4 && pOrdenado[j] > p){
					personas += 1;
				}else{
					break;
				}
			}
			System.out.println("Case #"+i+": "+personas);
		}
	}

}

package codejam2012.qr.dancing;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author fedez
 */
public class DancerSolver
{

    private static Logger logger = Logger.getLogger(DancerSolver.class.getName());

    public static int solve(int googlers, int[] scores, int suprises, int scoreTopass)
    {
        AtomicInteger surprisesLeft;
        int numberOfPasses = 0;
        int score, i, possible;

        surprisesLeft = new AtomicInteger(suprises);
        for (i = 0; i < googlers; i++)
        {
            score = scores[i];
            possible = isItPossible(score, surprisesLeft, scoreTopass);
            logger.log(Level.INFO, "Score:{0}, surprisesLeft:{1}, scoreTopass:{2}, result:{3}", new Object[]
                    {
                        score, surprisesLeft, scoreTopass, possible
                    });

            numberOfPasses += possible;
        }

        return numberOfPasses;
    }

    private static int isItPossible(double score, AtomicInteger surprisesLeft, int scoreTopass)
    {
        double remainder, leftValues, lowestValue;

        if (scoreTopass == 0)
        {
            return 1;
        }

        remainder = score - scoreTopass;
        if (remainder < 0)
        {
            return 0;
        }
        
        leftValues = remainder / 2d;
        if (remainder % 2 == 0)
        {
            lowestValue = leftValues;
        }
        else
        {
            lowestValue = Math.floor(leftValues);
        }
        if (scoreTopass - lowestValue <= 1)
        {
            return 1;
        }
        else if (scoreTopass - lowestValue <= 2 && surprisesLeft.get() > 0)
        {
            surprisesLeft.decrementAndGet();
            return 1;
        }
        else
        {
            return 0;
        }
    }
}
