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 es.uam.eps.abk.qualification2012;

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * Dancing With the Googlers
 *
 * You're watching a show where Googlers (employees of Google) dance, and then
 * each dancer is given a triplet of scores by three judges. Each triplet of scores
 * consists of three integer scores from 0 to 10 inclusive. The judges have very
 * similar standards, so it's surprising if a triplet of scores contains two
 * scores that are 2 apart. No triplet of scores contains scores that are more
 * than 2 apart.
 *
 * For example: (8, 8, 8) and (7, 8, 7) are not surprising.
 * (6, 7, 8) and (6, 8, 8) are surprising. (7, 6, 9) will never happen.
 *
 * The total points for a Googler is the sum of the three scores in that
 * Googler's triplet of scores. The best result for a Googler is the maximum
 * of the three scores in that Googler's triplet of scores.
 * Given the total points for each Googler, as well as the number of surprising
 * triplets of scores, what is the maximum number of Googlers that could have
 * had a best result of at least p?
 *
 * @author Alejandro
 */
public class B {

    private static void solve(InputStream in, PrintStream out) {
        Scanner scan = new Scanner(in);
        int T = scan.nextInt(); // test cases
        for (int t = 1; t <= T; t++) {
            int N = scan.nextInt(); // number of Googlers
            int S = scan.nextInt(); // number of surprising scores
            int p = scan.nextInt(); // best result

            int[] points = new int[N]; // total points
            for (int i = 0; i < N; i++) {
                points[i] = scan.nextInt();
            }

            int n = getGooglers(points, S, p);

            out.println("Case #" + t + ": " + n);
        }
    }

    private static int getGooglers(int[] points, int surprisingScores, int bestResult) {
        int n = 0;
        double[] avg = new double[points.length];
        for (int i = 0; i < points.length; i++) {
            avg[i] = 1.0 * points[i] / 3;
        }
        Arrays.sort(avg);
//        System.out.println(Arrays.toString(avg));
        for (int i = points.length - 1, j = 0; i >= 0 && j < surprisingScores; i--) {
            double m = Math.ceil(avg[i]);
            if ((m > 0.0) && (m < bestResult)) {
                avg[i] += 2.0 / 3;
                j++;
            }
        }
//        System.out.println(Arrays.toString(avg));
        for (int i = 0; i < points.length; i++) {
            double m = Math.ceil(avg[i]);
            if (m >= bestResult) {
                n++;
            }
        }
        for (int i = points.length - 1, j = 0; i >= 0 && j < surprisingScores; i--, j++) {
            avg[i] -= 2.0 / 3;
        }
        return n;
    }

    public static void main(String[] args) throws Exception {
        String file = null;
        file = "inputB2012.txt";

        file = "2012B-small-attempt0.in";

//        file = "A-large.in";

        InputStream in = new FileInputStream(file);
        PrintStream out = new PrintStream("output." + file);

        solve(in, out);

        in.close();
        out.close();
    }
}
