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 com.rahul.codejam;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

/**
 * Hello world!
 *
 */
public class App 
{
	private int inputlength;
	private int counter;
	
	public App(String filename) {
		fFileName = filename;
	}
	
    public static void main( String[] args ) throws IOException
    {
    	String fileName = args[0];
		String encoding = "utf-8";
		App test = new App(fileName);
		test.process();
    }
    
    protected void process() throws IOException {
		log("Reading from file.");

		StringBuilder text = new StringBuilder();
		String NL = System.getProperty("line.separator");
		Scanner scanner = new Scanner(new FileInputStream(fFileName), fEncoding);
		try {
			while (scanner.hasNextLine()) {
				if (inputlength == 0) {
					inputlength = Integer.parseInt(scanner.nextLine());
				} else {
					counter++;
					String output = String.format("Case #%d: %s", counter,processLine(scanner.nextLine()));
					System.out.println(output);
					text.append(output + NL);
				}
				//text.append(scanner.nextLine() + NL);
			}
			log("Writing to file named " + fFileName+".out" + ". Encoding: " + fEncoding);
		    Writer out = new OutputStreamWriter(new FileOutputStream(fFileName + ".out"), fEncoding);
		    try {
		      out.write(text.toString());
		    }
		    finally {
		      out.close();
		    }
		} finally {
			scanner.close();
		}
		log("Text read in: " + text);
	}
    
    protected String processLine(String s) {
		//Logic goes here
		String comp[] = s.split(" ");
		int googlers = Integer.parseInt(comp[0]);
		int maxsurprises = Integer.parseInt(comp[1]);
		int surprises = 0;
		int chasingScore = Integer.parseInt(comp[2]);
		int googlersGotChasingScores = 0;
		String scores[] = Arrays.copyOfRange(comp, 3, comp.length);
		System.out.println("scores length: " + scores.length);
		for(int i = 0; i < scores.length && i < googlers; i++) {
			if(checkChasingScore(Integer.parseInt(scores[i]), chasingScore)) {
				googlersGotChasingScores++;
			} else if(surprises < maxsurprises) {
				if(checkChasingScoreWithSurprise(Integer.parseInt(scores[i]), chasingScore)) {
					surprises++;
					googlersGotChasingScores++;
				}
			}
		}
		System.out.print(googlersGotChasingScores);
		return googlersGotChasingScores+"";
	}
    
    protected boolean checkChasingScore(int totalScore, int chasingScore) {
		boolean gotScore = false;
		switch (totalScore %3) {
		case 0:
			gotScore = totalScore/3 >= chasingScore;
			break;
		case 1:
		case 2:
			if(totalScore/3 + 1 <= totalScore)
				gotScore = (totalScore/3 + 1) >= chasingScore;
			break;
		}
		return gotScore;
	}
    
    protected boolean checkChasingScoreWithSurprise(int totalScore, int chasingScore) {
		boolean gotScore = false;
		switch (totalScore % 3) {
		case 0:
		case 1:
			if(totalScore/3 + 1 <= totalScore)
				gotScore = (totalScore/3 + 1) >= chasingScore;
			break;
		case 2:
			if(totalScore/3 + 2 <= totalScore)
			gotScore = (totalScore/3 + 2) >= chasingScore;
			break;
		}
		return gotScore;
	}

// PRIVATE
	private final String fFileName;
	private final String fEncoding = "utf-8";

	private void log(String aMessage) {
		System.out.println(aMessage);
	}
}
