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 jam2;

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

public class Test2 {
	public static void main(String argv[]){
		Test2 tb = new Test2();
		ArrayList<String> strin = tb.readFile("B-small-attempt0.in");
		ArrayList<ArrayList<Integer>> intin = tb.getInt(strin);
		
		tb.printInt(intin);
		
		ArrayList<String> strout = new ArrayList<String>();
		
		tb.computeDancer(intin, strout);
		
		tb.writeResult(strout, "outtest2_mall.txt");
	}
	
	public void computeDancer(ArrayList<ArrayList<Integer>> intin, 
			ArrayList<String> strout){
		if(intin==null || strout==null || intin.size()==0) return;
		int nTest = intin.get(0).get(0);
		for(int i=1; i<=nTest; ++i){
			
			int ndancer = intin.get(i).get(0);
			if(ndancer!=(intin.get(i).size()-3)){
				System.out.println("dancer do not match!");
				return;
			}
			
			int nsurprise = intin.get(i).get(1);
			int thresh = intin.get(i).get(2);
			final int tri =3;
			
			int ng = 0; //the googlers have score above threshold
			for(int j=3; j<intin.get(i).size(); ++j){
				int score = intin.get(i).get(j);
				if(score > (tri*(thresh-1))){
					ng++;
				}else if(score>(tri*(thresh-2)+1)){
					int div = score/tri;
					int residule = score%tri;
					if(nsurprise > 0){
						if(residule <=1 && div==0) continue; //
						ng++;
						nsurprise --;
					}
				}
			}
			
			//write out the results
			String line = "Case #"+i+": "+ng;
			System.out.println(line);
			strout.add(line);
		}
		
		
	}
	
	public void printInt(ArrayList<ArrayList<Integer>> intin){
		if(intin==null ) return;
		for(ArrayList<Integer> arr:intin){
			for(Integer i: arr){
				System.out.print(i+",");
			}
			System.out.println();
		}
	}
	
	public ArrayList<ArrayList<Integer>> getInt(ArrayList<String> strlist){
		if(strlist == null) return null;
		ArrayList<ArrayList<Integer>> intlist = new ArrayList<ArrayList<Integer>>();
		for(String s:strlist){
			ArrayList<Integer> tarr = new ArrayList<Integer>();
			String astr[] = s.split(" ");
			for(int i=0; i<astr.length; ++i){
				int itemp = Integer.parseInt(astr[i]);
				tarr.add(itemp);
			}
			intlist.add(tarr);
		}
		return intlist;
	}
	
	public ArrayList<String> readFile(String inname){
		if(inname == null) return null;
		
		ArrayList<String> arr = new ArrayList<String>();
		 try{
			 FileInputStream fstream = new FileInputStream(inname);
			 // Get the object of DataInputStream
			 DataInputStream in = new DataInputStream(fstream);
			 BufferedReader br = new BufferedReader(new InputStreamReader(in));
			 String strLine;
			 //Read File Line By Line
			 while ((strLine = br.readLine()) != null)   {
				 arr.add(strLine);
			 	}
			 //Close the input stream
			 in.close();
		 }catch (Exception e){//Catch exception if any
			 System.err.println("Error: " + e.getMessage());
		 }
		 
		 return arr;
	}
	
	public void writeResult(ArrayList<String> res, String fname){
		if(res == null || res.size()==0) return;
		try{
			FileWriter fstream = new FileWriter(fname);
			BufferedWriter out = new BufferedWriter(fstream);

			for(int i=0; i<res.size()-1;++i){
				out.write(res.get(i));
				out.newLine();
			}
			out.write(res.get(res.size()-1));
			out.close();
		}catch (Exception e){//Catch exception if any
			  System.err.println("Error: " + e.getMessage());
		  }
	}

}
