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

import java.awt.Container;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

import javax.swing.JFrame;
import javax.swing.JTextArea;


public class Dancing extends JFrame
{
	private final int WIDTH = 800;
	private final int HEIGHT = 400;
	private Container pane; 
	
	private String[] unformatted;
	private String[] formatted;
	private char[][] formattedCharArray;
	
	private int[] numberOfDancers;
	private int[] numberOfSurprises;
	private int[] theScoreToBeat;
	
	private int[][] theScores;
	private boolean[][] wasNatural;
	
	private int[] numberOfNaturalWinners;
	private int[] numberOfSurprisingWinners;
	private int[] numberOfWinners;
	
	private int numberOfLines;
	
	private int[] naturals = {0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10}; 
	private int[] surprises = {0, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10};
	
	private JTextArea input, output;
	
	
	
	private Scanner scanner;
	private PrintWriter out;
	
	
	public Dancing() throws IOException
	{
		pane = new Container();
		pane = getContentPane();
		
		scanner = new Scanner(new File("c:/users/Christopher/Desktop/input.in"));
		out = new PrintWriter(new FileWriter("c:/users/Christopher/Desktop/output.out")); 
		
		numberOfLines = Integer.parseInt(scanner.nextLine());
		
		
		unformatted = new String[numberOfLines];
		formatted = new String[numberOfLines];
		
		numberOfDancers = new int[numberOfLines];
		numberOfSurprises = new int[numberOfLines];
		theScoreToBeat = new int[numberOfLines];
		
		numberOfNaturalWinners = new int[numberOfLines];
		numberOfSurprisingWinners = new int[numberOfLines];
		numberOfWinners = new int[numberOfLines];
		
		input = new JTextArea(100, numberOfLines);
		input.setSize(300,200);
		input.setLocation (10, 10);
		
		output = new JTextArea(120, numberOfLines);
		output.setSize(300,200);
		output.setLocation(410, 10);
		
		pane.setLayout(null);
		pane.add(input);
		pane.add(output);
		
		theScores = new int[numberOfLines][];
		wasNatural = new boolean[numberOfLines][];		

		for (int i = 0; i < numberOfLines; i++)
		{
			numberOfDancers[i] = scanner.nextInt();
			numberOfSurprises[i] = scanner.nextInt();
			theScoreToBeat[i] = scanner.nextInt();
			
			input.append(numberOfDancers[i] + " " + numberOfSurprises[i] + " " + theScoreToBeat[i] + " ");
			
			theScores[i] = new int[numberOfDancers[i]];
			wasNatural[i] = new boolean[numberOfDancers[i]];
			
			for (int j = 0; j < numberOfDancers[i]; j++)
			{
				theScores[i][j] = scanner.nextInt();
				if (j < numberOfDancers[i] - 1)
					input.append(theScores[i][j] + " ");
				else
					input.append(theScores[i][j] + "\n");
			}
			
		}
		
		for (int i = 0; i < numberOfLines; i++)
		{
			numberOfWinners[i] = findWinners(i);
			output.append("Case #" + (i + 1) + ": " + numberOfWinners[i] + "\n");
			out.println("Case #" + (i + 1) + ": " + numberOfWinners[i] + "\n");
		}
		
		
		
	/*	for (int i = 0; i < numberOfLines; i++)
		{
			formatted[i] = new String(formattedCharArray[i]);
			formatted[i] = "Case #" + (i + 1) + ": " + formatted[i];
			output.append(formatted[i] + "\n");
			out.println(formatted[i]);
		}
		*/
		
		scanner.close();
		out.close();
		
		setVisible(true);
		setSize(WIDTH, HEIGHT);
		setTitle("Tongues");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		
		
	}
	
	public static void main(String args[]) throws IOException
	{
		Dancing awesome = new Dancing();
	}
	
	int findWinners(int whichLine)
	{
		
		numberOfSurprisingWinners[whichLine] = 0;
		
		for (int i = 0; i < numberOfDancers[whichLine]; i++)
		{
			if (naturals[theScores[whichLine][i]] >= theScoreToBeat[whichLine])
			{
				numberOfNaturalWinners[whichLine]++;
				wasNatural[whichLine][i] = true;
			}
		}
		
		for (int i = 0; i < numberOfDancers[whichLine]; i++)
		{
			if (surprises[theScores[whichLine][i]] >= theScoreToBeat[whichLine] && wasNatural[whichLine][i] == false)
			{
				numberOfSurprisingWinners[whichLine]++;
			}
		}
		
		
		if (numberOfSurprisingWinners[whichLine] > numberOfSurprises[whichLine])
		{
			numberOfSurprisingWinners[whichLine] = numberOfSurprises[whichLine];
		}
		
		return numberOfNaturalWinners[whichLine] + numberOfSurprisingWinners[whichLine];
	}
}