import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;


public class Dancing {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// read input file
		File file = new File("B-small-attempt4.in");
		//File file = new File("input.txt");
		BufferedReader br = new BufferedReader(new FileReader(file));
		String ln = "";
		int count = Integer.parseInt(br.readLine());

		// write output file
		File out = new File("outB.txt");
		BufferedWriter bw = new BufferedWriter(new FileWriter(out));
		
		int y = 0;
		for (int i=0; i < count; i++){
			ln = br.readLine();
			y = getY(ln);
			bw.write("Case #" + (i+1) + ": " + y);
			bw.newLine();
		}
		bw.close();
	}
	
	private static int getY(String str) {
		String[] data = str.split(" ");
		int n = Integer.parseInt(data[0]);
		int s = Integer.parseInt(data[1]);
		int p = Integer.parseInt(data[2]);
		int[] t = new int[n];
		for (int i=0; i < n; i++){
			t[i] = Integer.parseInt(data[i+3]);
		}
		int y = 0;
		int base = 0;
		for(int j=0; j < t.length; j++){
			base = t[j] / 3;
			if(base >= p) { y++; }
			else if(base == p-1){
				if(t[j] - (base+p) > base-1 && t[j] > 0){
					y++;
				} else if(s>0 && t[j] - (base+p) > base-2 && t[j] > 0){
					s -= 1;
					y++;
				}
			} else if(base == p-2){
				if(s > 0 && t[j] - (base+p) > base-1 && t[j] > 0){
					s -= 1;
					y++;
				}
			}
		}
		
		return y;
	}

}

package QualificationRound;

	import java.io.BufferedReader;
	import java.io.File;
	import java.io.FileNotFoundException;
	import java.io.FileReader;
	import java.io.IOException;
	import java.util.ArrayList;
import java.util.Dictionary;
import java.util.regex.Pattern;

	public class B
	{
		public B()
		{

		}
		public int solveLine(String in)
		{
			String[] input = in.split(" ");
			int N = Integer.parseInt(input[0]); //N - number of googlers
			int S = Integer.parseInt(input[1]); //S - suprising results
			int P = Integer.parseInt(input[2]); //P - at lest best result criteria
			int P3 = P * 3;
			int Pmin = P3-3;
			int Sleft = S;
			int totalPoints = 0;
			int maxNumOfGooglerDancers = 0;
			if (Pmin == 0)
			{
				Pmin = 2;
			}
			for (int i=0; i<N; i++)
			{
				totalPoints = Integer.parseInt(input[3 + i]);
				if (totalPoints < P3 ) //if the totalScore is less we need to check for special cases 
				{
					if ( totalPoints > Pmin)
					{
						maxNumOfGooglerDancers++;
					}
					else
					if (((totalPoints == Pmin)||((totalPoints == (Pmin-1)))) && (Sleft > 0))
					{
						maxNumOfGooglerDancers++;
						Sleft--;
					}
					
				}
				else
				{
					maxNumOfGooglerDancers++;
				}
			}
			return maxNumOfGooglerDancers;
		}
		
		
				
		public static void calcFromFile(String fileName)
		{
		      
				File file = new File(fileName);
		        BufferedReader reader = null;

		        try {
		            reader = new BufferedReader(new FileReader(file));
		            String sentence = null;
		            // repeat until all lines is read
		            int numOfLine = 1;
		            B q2 = new B();
		            sentence = reader.readLine();
		       
		            	//Read the n test cases
		            	while ((sentence = reader.readLine()) != null) 
			            {
		            		System.out.println("Case #" + numOfLine++ + ": "+q2.solveLine(sentence));
			            }

		            	

		        } catch (FileNotFoundException e) {
		            e.printStackTrace();
		        } catch (IOException e) {
		            e.printStackTrace();
		        } finally {
		            try {
		                if (reader != null) {
		                    reader.close();
		                }
		            } catch (IOException e) {
		                e.printStackTrace();
		            }
		        }
		}
	}


