package googlers;

import java.util.Scanner;
import java.util.PriorityQueue;
import java.util.Comparator;
public class Googlers {
	
	public static void main(String[] args) {
		
		int n,s,p,count=0,t;		
		Scanner sin=new Scanner(System.in);
		
		t=Integer.parseInt(sin.nextLine());
		
		
		int result[]=new int[t];
		int j=0;
		
		if(t>=1 && t<=100)
		{
		for (int k = 0; k < t; k++) {
		count=0;	
		
			
        String ip = sin.nextLine();
        
        String[]tokens=ip.split(" ");
		
		
		n=Integer.parseInt(tokens[0]);
		s=Integer.parseInt(tokens[1]);
		p=Integer.parseInt(tokens[2]);
		
		if( (s>=0 && s<=n) && (p>=0 && p<=10) )
		{
		int[] total=new int[n];
		
		
		for (int i = 0; i < n; i++)
        {
            total[i] = Integer.parseInt(tokens[i+3]);
        }
		
		Comparator comparator=new PointComparator();
		PriorityQueue pq=new PriorityQueue<Point>(1, comparator);
		
		for (int i = 0; i < n; i++)
		{
			
			int x=total[i]/3;
			int r=total[i]%3;
			if(x>=p)
				count++;
			else if(x<(p-2))
				continue;
			else
			{
				//System.out.println("enter "+x+" "+(p-2));
				if(p-x==1)
				{
					Point temp=new Point();
					temp.q=x;
					temp.r=r;
					pq.add(temp);
				}
				else  // p-x=2
				{
					if(r==0)
						continue;
					else
					{
						Point temp=new Point();
						temp.q=x;
						temp.r=r;
						pq.add(temp);
					}				
					
				}
					
			}
			//System.out.println("hi "+pq.size());
			
		}
		
		
		
		while(pq.size()!=0)
		{
			Point temp=(Point)pq.remove();
			if(p-temp.q==1 && temp.q!=0)
			{
				if(temp.r>=1)
					count++;
				else
				{
					if(s!=0)
					{
						s--;
						count++;
					}
				}
			}
			else if(p-temp.q==2)
			{
				if(s!=0 && (temp.q+temp.r)>=p)
				{
					s--;
					count++;
				}
			}
			
				
		}
		
		//System.out.println(p);
		
		result[j++]=count;
		
		}
		}
		
		for (int i = 0; i < t; i++) 
		{
			System.out.println("Case #"+(i+1)+": "+result[i]);
		}
		}
		
	}
        
        
		
		/*Point x=new Point();
		x.q=8;
		Point y=new Point();
		y.q=6;
		Point z=new Point();
		z.q=7;
		
		pq.add(x);
		pq.add(y);
		pq.add(z);
		*/
		
		
		
		
	

}

class PointComparator implements Comparator<Point>
{
    @Override
    public int compare(Point x, Point y)
    {
        // Assume neither string is null. Real code should
        // probably be more robust
        if (x.q < y.q)
        {
            return 1;
        }
        if (x.q  > y.q)
        {
            return -1;
        }
        return 0;
    }
}



class Point
{
	int q,r;

	public int getQ() {
		return q;
	}

	public void setQ(int q) {
		this.q = q;
	}

	public int getR() {
		return r;
	}

	public void setR(int r) {
		this.r = r;
	}
	
	
}

package GoogleDance;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class GoogleDance {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try{
			String userDir = System.getProperty("user.dir"); //get working directory
			userDir.replaceAll("['\']", "\\"); // replace all chars '\' with '\\' in the string
			File file = new File(System.getProperty("user.dir") + "\\QualificationRound\\GoogleDance\\in-out\\B-small-attempt0.in");
	        Scanner fileScanner = new Scanner(file);
	        //delimiter is how input text is set up in this case it's the new line char
	        fileScanner.useDelimiter(System.getProperty("line.separator")); 
	        //declared for file writing
	        BufferedWriter outFile = new BufferedWriter(new FileWriter(System.getProperty("user.dir") + "\\QualificationRound\\GoogleDance\\in-out\\B-small.out"));
			int counter, inCounter, deepCounter, masterCounter, numCases, startIndex, numPpl, suprisingScores, minScore, currentNum, maxH, result;
			int judgeHigh, judgeLow;
			ArrayList<Integer> intList = new ArrayList<Integer>();
			int [] judgeScores = new int[3];
			String inputText;
			boolean suprisingScoresReal;
			numCases = Integer.parseInt(fileScanner.nextLine());
			for(masterCounter = 1; masterCounter <= numCases; masterCounter++){
				inputText = fileScanner.nextLine();
				startIndex = 0;
				result = 0;
				for( counter = 0; counter < inputText.length(); counter ++){
					if (inputText.charAt(counter) == ' ') 
					{
						intList.add(Integer.parseInt(inputText.substring(startIndex, counter))); 
						startIndex = counter + 1;
					}    			
				}
				intList.add(Integer.parseInt(inputText.substring(startIndex, counter))); 
				numPpl = intList.get(0);
				suprisingScores = intList.get(1);
				minScore = intList.get(2);
				intList.remove(0);
				intList.remove(0);
				intList.remove(0);
				if(suprisingScores == 0)
					suprisingScoresReal = false;
				else
					suprisingScoresReal = true;
				for(counter = 0; counter < intList.size(); counter++){
					if(intList.get(counter) <= 2){
						for(inCounter = 0; inCounter < intList.get(counter); inCounter++)
							judgeScores[inCounter] = 1;
						for(deepCounter = inCounter; deepCounter < 3; deepCounter++)
							judgeScores[deepCounter] = 0;
						maxH = 0;
					}
					else{
						currentNum = intList.get(counter) / 3;
						judgeScores[0] = currentNum;
						judgeScores[1] = currentNum;
						judgeScores[2] = currentNum;
						maxH = intList.get(counter) - (currentNum + currentNum + currentNum);
					}
					deepCounter = 0;
					if(maxH > 0)
						for(inCounter = 0; inCounter < maxH; inCounter++){//distribute extra points (from /3)
							judgeScores[deepCounter] = judgeScores[deepCounter] + 1;
							deepCounter++;
							if(deepCounter >= 3)
								deepCounter = 0;
						}
					Arrays.sort(judgeScores); //sorted from low (position[0]) to high (position[2])
					
					if(judgeScores[2] >= minScore)
						result++;
					else if(suprisingScoresReal == true && judgeScores[2] != 0){
						if(judgeScores[2] == judgeScores[1] && suprisingScores != 0 && judgeScores[2] + 1 >= minScore){
						result++;
						suprisingScores--;
						}
					}
				}
				//System.out.println("suprisingScores :" + suprisingScores);
				//outFile.write("suprisingScores :" + suprisingScores + "\n");
			System.out.println("Case #" + masterCounter + ": " + result);
        	outFile.write("Case #" + masterCounter + ": " + result + "\n");
        	intList.clear();
			}
			
	        fileScanner.close();
	        outFile.close();
		}
		catch (FileNotFoundException e) {
			System.out.println("File not found"); e.printStackTrace();
		}
		catch (IOException e) {
			System.out.println("IOException");
		}
	}

}
