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 google.solver;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

public class ProblemPackageCreator  implements ChallengeConstants{

	private final String packageName;
	private String directoryName;
	private String challengeDef;
	private String readerName;
	private String challengeName;
	private String packagePath;


	ProblemPackageCreator(String packageName){
		this.packageName = packageName;
		packagePath = "google.contest."+packageName;
		directoryName = BASE_DIR+DELIMITER+packageName;
		challengeDef = BASE_DIR+DELIMITER+packageName+DELIMITER+CHALLENGE_DEFINITION;
		readerName = packageName.substring(0,1).toUpperCase()+packageName.substring(1)+"Reader";
		challengeName = packageName.substring(0,1).toUpperCase()+packageName.substring(1)+"Challenge";
	}

	private void create() {
		try{
			createDirectory();
			createTestIn();
			createChallengeDefinition2();
			createReader();
			createChallenge();
		}
		catch(Exception e){
			throw new RuntimeException(e);
		}
	}

	private void createTestIn() {
		writeToPath(TEST_IN, "");
		
	}

	private void createChallenge() {
		String def ="package "+packagePath+";\n\n"+
				"import google.loader.Challenge;\n"+
				"import google.problems.AbstractChallenge;\n\n"+
				"public class "+challengeName+" extends AbstractChallenge implements Challenge {\n\n"+
				"public "+challengeName+"(int number) {\n"+
				"super(number);\n"+
				"setResult(\"\");\n"+
				"}\n"+
				"}\n";
		writeJava(challengeName, def);
	}

	private void createReader() {
		String def = "package "+packagePath+";\n\n"+
				"import google.loader.Challenge;\n"+
				"import google.problems.AbstractReader;\n\n"+
				"public class "+readerName+" extends AbstractReader {\n \n"+
				"@Override\n"+
				"protected Challenge createChallenge(int number) {\n"+
				"int theLine = getActualLine();\n"+
				"String[] lines = getLines();\n"+
				"int value = Integer.parseInt(getLines()[theLine]);\n"+
				challengeName+" chal = new "+challengeName+"(number);\n"+
				"setActualLine(theLine+1);\n"+
				"return chal;\n"+
				"}\n"+
				"\n"+
				"}\n";

		writeJava(readerName, def);
	}
	
	private void writeToPath(String fileName, String text){
		write(directoryName+DELIMITER+fileName, text);
	}

	private void writeJava(String baseName, String text) {
		writeToPath(baseName+".java", text);
	}

	private void createChallengeDefinition() {
		String def = "fileName="+TEST_IN+"\n"+
				"# fileName=A-small-practice.in\n"+
				"# fileName=A-large-practice.in\n"+
				"# fileName=B-small-practice.in\n"+
				"# fileName=B-large-practice.in\n"+
				"# fileName=C-small-practice.in\n"+
				"# fileName=C-large-practice.in\n"+
				"readerClassName="+packagePath+"."+readerName;
		write(challengeDef, def);
	}

	private void createChallengeDefinition2() {
		String def = "fileName="+TEST_IN+"\n"+
				"# fileName="+packageName+"-small-practice.in\n"+
				"# fileName="+packageName+"-large-practice.in\n"+
				"readerClassName="+packagePath+"."+readerName;
		write(challengeDef, def);
	}
	
	private void createDirectory() throws Exception{
		File file = new File(directoryName);
		if(! file.exists()){
			file.mkdir();
		}else{
			throw new RuntimeException("alreadyExisting");
		}
	}

	public static void main(String[] args) {
		String packageName =CHALLENGE_NAME;
		ProblemPackageCreator creator = new ProblemPackageCreator("A");
		creator.create();
		creator = new ProblemPackageCreator("B");
		creator.create();
		creator = new ProblemPackageCreator("C");
		creator.create();
	}

	public static void write(String aFileName, String text) {
		try{
			FileWriter fstream = new FileWriter(aFileName);
			BufferedWriter out = new BufferedWriter(fstream);
			out.write(text);
			out.close();
		}catch (Exception e){
			throw new RuntimeException(e);
		}
	}


}
