/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 3/3/12
 * Time: 11:00 AM
 * To change this template use File | Settings | File Templates.
 */

import SRMLib.MathLibrary;
import SRMLib.TestSRMLib;
import com.sun.org.apache.bcel.internal.generic.F2D;

import java.io.*;
import java.util.*;
import java.util.zip.Inflater;

public class SRM {
    public static void main(String[] args) throws IOException {
        //TestSRMLib.run();
        codeJam1.main();

        return;
    }
}
class codeJam1 {
    public static void main() throws IOException {
        String inputPath = "E:\\input.txt";
        String outputPath = "E:\\output.txt";
        BufferedReader input = new BufferedReader(new FileReader(inputPath));
        BufferedWriter output = new BufferedWriter(new FileWriter(outputPath));

        String line;
        line = input.readLine();
        int T = Integer.parseInt(line);
        for (int i = 1; i <= T; ++i) {
            line = input.readLine();
            String[] words = line.split(" ");
            int N = Integer.parseInt(words[0]);
            int S = Integer.parseInt(words[1]);
            int p = Integer.parseInt(words[2]);
            int n = 0;
            int res = 0;

            for (int j = 3; j < words.length; ++j) {
                if (p == 0) {
                    res++;
                    continue;
                }

                int t = Integer.parseInt(words[j]);
                if (p == 1) {
                    if (t > 0)
                        res++;
                    continue;
                }
                if (t >= 3 * p - 2)
                    res++;
                else if (t >= 3 * p - 4)
                    n++;
            }

            res += Math.min(n, S);
            output.write("Case #" + i + ": " + res);
            output.newLine();
        }

        input.close();
        output.close();
    }
}

package qualification;

import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.Vector;

public class ProblemB {
	
	static Scanner scan = new Scanner(System.in);
	
	public static void main(String[] args) {

		

		int cases = scan.nextInt();
		
		for ( int i = 1; i <= cases; i++ ) {
			
			System.out.println("Case #" + i + ": " + solveCase());
			
			
		}

	}
	
	public static int solveCase() {
		int numGooglers = scan.nextInt();
		int numSurprising = scan.nextInt();
		int p = scan.nextInt();
		
		Vector<Triplet> containsGreaterThanP = new Vector<Triplet>();
		Vector<Triplet> containsPminus1 = new Vector<Triplet>();
		
		for ( int j = 0; j < numGooglers; j++ ) {
			Triplet t = new Triplet();
			
			int score = scan.nextInt();
			int n = Math.round( score / 3f );
			int n_2 = score - 2*n;
			
			// Ordered triplets
			if ( n_2 > n ) {
				t.add(n_2);
				t.add(n);
				t.add(n);
			} else {
				t.add(n);
				t.add(n);
				t.add(n_2);
			}
			
			if ( t.containsGreaterThan(p) ) {
				// Check if it can be made surprising
				containsGreaterThanP.add(t);
			} else if ( t.contains(p-1) > 1 && p > 1 && t.contains(0) <= 1) {
				containsPminus1.add(t);
			}
		}
//				System.out.println("Googlers: " + numGooglers);
//		System.out.println("Surprising: " + numSurprising);
//		System.out.println("P: " + p);
//		System.out.println(containsGreaterThanP);
//		System.out.println(containsPminus1);
		
		return containsGreaterThanP.size() + Math.min(numSurprising, containsPminus1.size());
		

	}
	
	static class Triplet {
		int[] values = new int[3];
		
		int i = 0;
		
		public void add(int a) {
			if ( i > 2)
				throw new InputMismatchException("Bad input");
			
			values[i] = a;
			i++;
		}
		
		public int contains(int v) {
			
			int retval = 0;
			
			retval += values[0] == v ? 1 : 0;
			retval += values[1] == v ? 1 : 0;
			retval += values[2] == v ? 1 : 0;
			
			return retval;

		}
		
		public boolean containsGreaterThan(int v) {
			// Ordered triplets
			return values[0] >= v;
		}
		
		public boolean allEqual() {
			return values[0] == values[1] && values[1] == values[2];
		}
		
		public String toString() {
			return "(" + values[0] + " " + values[1] + " " + values[2] + ")";
		}
	}
}
