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 com.google.code.p_b;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;

public class Main {

	private static final String fromFile = "D:\\hobbies & work\\programing\\CodeJamTextFiles\\2012\\B-large.in";
	private static final String toFile = "D:\\hobbies & work\\programing\\CodeJamTextFiles\\2012\\B-large.out";

	
	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		System.out.println("Problem B start");
		
		try {

			FileInputStream fstream = new FileInputStream(fromFile);

			DataInputStream in = new DataInputStream(fstream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			
			FileWriter fstreamout = new FileWriter(toFile);
			BufferedWriter out = new BufferedWriter(fstreamout);
			
			String strLine;
			boolean firstLine = true;
			int i = 1;
			while ((strLine = br.readLine()) != null) 
			{
				if (!firstLine)
				{
					System.out.println(strLine);
					System.out.println("Case #" + i + ": " + ansForLine(strLine) + "\n");

					out.write("Case #" + i + ": " + ansForLine(strLine) + "\n");
					i++;
				}
				else
				{
					firstLine = false;
				}
			}
			out.close();
			in.close();
		} catch (Exception e) {
			System.err.println("Error: " + e.getMessage());
		}
		
		System.out.println("Problem B end");
	}


	private static int ansForLine(String strLine) 
	{
		String [] splitedLine = strLine.split(" ");
		int nRes = Integer.parseInt(splitedLine[0]);
		int nSurprises = Integer.parseInt(splitedLine[1]);
		int nMax = Integer.parseInt(splitedLine[2]);
		System.out.println("res: " + nRes + ", surprises: " + nSurprises +", max: " + nMax);

		int count = 0;
		
		for (int i = 3; i < splitedLine.length; i++)
		{
			int j = Integer.parseInt(splitedLine[i]);
			int avg = j / 3;
			int m = j % 3;
			
			if (j == 0)
			{
				if (nMax == 0)
					count ++;
				continue;
			}
			
			if (avg >= nMax)
			{
				count ++;
			}
			else if (avg + 1 >= nMax)
			{
				if (m == 0 && nSurprises > 0)
				{
					count ++;
					nSurprises --;
				}
				else if (m == 1 || m == 2)
				{
					count ++;
				}
			}
			else if (avg + 2 >= nMax)
			{
				if (m == 2 && nSurprises > 0)
				{
					count ++;
					nSurprises --;
				}
			}
		}
		
		return count;
	}

}
