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

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

/**
 *
 * @author sergeiw
 */
public class B {

    public static String FILE_SEPARATOR = System.getProperty("file.separator");
    public static String FILE_INPUT_DIR = System.getProperty("user.dir") + FILE_SEPARATOR + "files" + FILE_SEPARATOR;
    public static String FILE_OUTPUT_DIR = System.getProperty("user.dir") + FILE_SEPARATOR + "files" + FILE_SEPARATOR;

    public static void main(String[] args) throws FileNotFoundException, IOException {
        //String filename = "B-example.in";
        //String filename = "B-small-attempt0.in";
        //String filename = "B-small-attempt1.in";
        //String filename = "B-small-attempt2.in";
        //String filename = "B-small-attempt3.in";
        //String filename = "B-small-attempt4.in";
        //String filename = "B-small-attempt5.in";
        String filename = "B-small-attempt6.in";
        //String filename = "B-large.in";
        File fileOut = new File(FILE_INPUT_DIR + filename.replace(".in", ".out"));
        FileWriter fw = new FileWriter(fileOut);
        File file = new File(FILE_INPUT_DIR + filename);
        Scanner scanner = new Scanner(file);
        try {
            int cases = scanner.nextInt();
            scanner.nextLine();
            int casenum = 1;
            

            while (scanner.hasNextLine()) {

                int solution = 0;
                
                
                int N = scanner.nextInt();
                int S = scanner.nextInt();
                int p = scanner.nextInt();
                
                int minScore = (p * 3) - 4;
                if (minScore < 0)
                    minScore = p;
                
                for (int i = 0; i < N; i++) {
                    int score = scanner.nextInt();
                    
                    for (int q = p; q >= 0; q--) {
                        if (score > q*3) {
                            solution++;
                            print(String.format("%d %d %d +", q, q, q ));
                            break;
                        }
                        if (score >= ((q*3-2)) && score <= (q*3)) {
                            if (q >= p)
                                solution++;                                                                
                            
                            if (score == (q*3)-1) 
                                print(String.format("%d %d %d", q, q, q-1 ));
                            else if (score == (q*3)-2) 
                                print(String.format("%d %d %d", q, q-1, q-1 ));
                            else
                                print(String.format("%d %d %d", q, q, q ));
                            break;
                        }
                        if ( score == ((q*3)-4) || score == ((q*3)-3) ) {
                            print(String.format("score: %d q: %d", score, q));                            
                            if (S-1 >= 0 && q >= p && q > 1) {                                
                                S--;
                                if (score == (q*3)-4) 
                                    print(String.format("%d %d %d (*)", q, q-2, q-2 ));
                                else 
                                    print(String.format("%d %d %d (*)", q, q-1, q-2 ));
                                solution++;
                                break;
                            }
                            
                            
                        }                     
                    }
                    print(String.format("score: %d, min: %d, sol: %d, S: %d", score, p, solution, S));    
                    
                    /*if (score >= minScore) {
                        if (score == 0 && minScore == 0) {
                            solution++;
                        } else {
                            if ((score == minScore || score == (minScore + 1))) {
                                print(String.format("s: %d min: %d", score, minScore));                            
                                S--;
                                if (S >= 0) {                                
                                    solution++;
                                }

                            } else {
                                solution++;
                            }
                        }
                    } else {
                        //print("LOWER");                        
                        for (int q = p - 1; q >= 2; q--) {
                            if ( score == ((q*3)-4) || score == ((q*3)-3) ) {
                                S--;
                                print(String.format("LOWER: S: %d", S));                                
                                break;
                                * 
                            }                            
                        }
                        
                    }                    
                    print(String.format("score: %d, min: %d, sol: %d, S: %d", score, minScore, solution, S));    
                    */
                    
                }
                //if (S < 0) solution = 0;
                
                print(String.format("Case #%d: [%s]", casenum, solution));
                fw.write(String.format("Case #%d: %s\n", casenum, solution));
                casenum++;
                print("");

            }
        } finally {
            scanner.close();
            fw.close();
        }

    }

    private static void print(String line) { System.out.println(line); };
    private static void print(int num) { print(String.valueOf(num)); };

    private static void print(int[] arr) {
        for(int i=0;i<arr.length;i++)
            System.out.print(String.valueOf(arr[i])+" ");
        System.out.println();
    };
    private static void print(String[] arr) {
        for(int i=0;i<arr.length;i++)
            System.out.print(arr[i]+" ");
        System.out.println();
    };

}
