import java.util.*;
import java.io.*;

public class DancingWithTheGooglers
{
    public DancingWithTheGooglers()
    {
        Scanner inFile = null;
        try
        {
            inFile = new Scanner(new File("inputB.txt"));
        }
        catch(Exception e)
        {
            System.out.println("Problem opening input file. Exiting...");
			System.exit(0);
        }
        int t = inFile.nextInt();
        
        int [] results = new int [t];
        DancingWithTheGooglersMax [] rnc = new DancingWithTheGooglersMax[t];
        
        int i, j;
        int [] scores;
        int s, p;
        for(i = 0; i < t; i++)
        {
            scores = new int [inFile.nextInt()];
            s = inFile.nextInt();
            p = inFile.nextInt();
            for(j = 0; j < scores.length; j++)
                scores[j] = inFile.nextInt();
            
            rnc[i] = new DancingWithTheGooglersMax(i, scores, s, p, results);
            rnc[i].start();
        }
        inFile.close();
        
        boolean done = false;
        
        while(!done)
        {
            done = true;
            for(i = 0; i < t; i++)
                if(rnc[i].isAlive())
                {
                    done = false;
                    break;
                }
        }
        
        PrintWriter outFile = null;
        try
        {
            outFile = new PrintWriter(new File("outputB.txt"));
        }
        catch(Exception e)
        {
            System.out.println("Problem opening output file. Exiting...");
			System.exit(0);
        }
        
        for(i = 0; i < results.length; i++)
            outFile.printf("Case #%d: %d\n", i+1, results[i]);
        outFile.close();
    }
    
    public static void main(String [] args)
    {
        new DancingWithTheGooglers();
    }
    
    private class DancingWithTheGooglersMax extends Thread
    {
        int id;
        int s, p;
        int [] results, scores;
        
        public DancingWithTheGooglersMax(int i, int [] aScores, int aS, int aP,int [] res)
        {
            id = i;
            s = aS;
            p = aP;
            results = res;
            scores = aScores;
        }
        
        public void run()
        {
            int a = 0, b = 0;
            
            if(p == 0)
                results[id] = scores.length;
            else if(p == 1)
            {
                int y;
                y = 3*p - 3;
                
                for(int i = 0; i < scores.length; i++)
                    if(scores[i] > y)
                        a++;
                    else if(scores[i] > 0)
                        b++;
                
                b = Math.min(b, s);
                results[id] = a+b;
            }
            else
            {
                int y, z;
                y = 3*p - 3;
                z = 3*p - 5;
                
                for(int i = 0; i < scores.length; i++)
                    if(scores[i] > y)
                        a++;
                    else if(scores[i] > z)
                        b++;
                
                b = Math.min(b, s);
                results[id] = a+b;
            }
        }
    }
}
package codejam2012;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.PrintStream;

public class ProblemB
{
	public static void main(String[] args) throws Exception
	{
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintStream out = System.out;
		out = new PrintStream("out.txt");
		
		int T = Integer.parseInt(in.readLine());
		
		for (int t = 0; t < T; t++)
		{
			String[] tok = in.readLine().split(" ");
			int N = Integer.parseInt(tok[0]);
			int S = Integer.parseInt(tok[1]);
			int p = Integer.parseInt(tok[2]);
			
// BRUTE FORCE
//			int ans = 0;
//			
//			for (int s1 = 0; s1 <= 10; s1++)
//			for (int s2 = s1; s2 <= s1+2; s2++)
//			for (int s3 = s2; s3 <= s1+2; s3++)
//			for (int s4 = 0; s4 <= 10; s4++)
//			for (int s5 = s4; s5 <= s4+2; s5++)
//			for (int s6 = s5; s6 <= s4+2; s6++)
//			for (int s7 = 0; s7 <= 10; s7++)
//			for (int s8 = s7; s8 <= s7+2; s8++)
//			for (int s9 = s8; s9 <= s7+2; s9++)
//			{
//				int p1 = Integer.parseInt(tok[3]);
//				int p1s = (s1+2 == s3) ? 1 : 0;
//				int p1t = (s3 >= p) ? 1 : 0;
//				if (s1+s2+s3 != p1) continue;
//				
//				if (N > 1)
//				{
//					int p2 = Integer.parseInt(tok[4]);
//					int p2s = (s4+2 == s6) ? 1 : 0;
//					int p2t = (s6 >= p) ? 1 : 0;
//					if (s4+s5+s6 != p2) continue;
//					
//					if (N > 2)
//					{
//						int p3 = Integer.parseInt(tok[5]);
//						int p3s = (s7+2 == s9) ? 1 : 0;
//						int p3t = (s9 >= p) ? 1 : 0;
//						if (s7+s8+s9 != p3) continue;
//						if (p1s+p2s+p3s != S) continue;
//						if (p1t+p2t+p3t > ans) ans = p1t+p2t+p3t;
//					}
//					else
//					{
//						if (p1s+p2s != S) continue;
//						if (p1t+p2t > ans) ans = p1t+p2t;
//					}
//				}
//				else
//				{
//					if (p1s != S) continue;
//					if (p1t > ans) ans = p1t;
//				}
//			}
// END BRUTE FORCE
			
			int with = 0, without = 0, either = 0, other = 0;
			for (int i = 3; i < tok.length; i++)
			{
				int total = Integer.parseInt(tok[i]);
				
				if (total == 0)
				{
					if (p == 0) without++;
				}
				else if (total == 1)
				{
					if (p <= 1) without++;
				}
				else if (total < 29)
				{
					if (total >= 3*p-2) either++;
					else if (total >= 3*p-4) with++;
					else other++;
				}
				else without++;
			}
			
			int ans = with + without + either;
			if (with > S) ans = S + without + either;
			else if (S > with + either + other) ans = 0;
			out.printf("Case #%d: %d\n", t+1, ans);
		}
		
		if (out != System.out) out.close();
	}
}
