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

public class DancingWithGooglers {

  public static class Googlers {

    public int T;
    public int surp;
    public boolean surprising;
    public boolean pSurprising;
    public boolean antiSurprising;
    public boolean pAntiSurprising;

    public Googlers(int T, int surp) {
      this.T = T;
      this.surp = surp;
    }

    public void set(int a, int b, int c) {
      if (c >= 0 && (a + b + c) == T) {
        int diff = (Math.max(a, Math.max(b, c)) - Math.min(a, Math.min(b, c)));
        if (diff <= 2) {
          if (diff == 2) {
            if (a >= surp || b >= surp || c >= surp) {
              pSurprising = true;
            } else {
              surprising = true;
            }
          } else {
            if (a >= surp || b >= surp || c >= surp) {
              pAntiSurprising = true;
            } else {
              antiSurprising = true;
            }
          }
        }
      }
    }
  }

  public static void main(String... args) throws IOException {
//    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    BufferedReader reader = new BufferedReader(new FileReader("B-large.in"));
//    PrintWriter writer = new PrintWriter(System.out);
    PrintWriter writer = new PrintWriter("B-large.out");

    int len, cases = Integer.parseInt(reader.readLine());
    List<Googlers> satisfied = new ArrayList<Googlers>();
    List<Googlers> unsatisfied = new ArrayList<Googlers>();
    String[] inputs;
    int N, S, p;
    for (int i = 1; i <= cases; i++) {
      inputs = reader.readLine().split(" ");
      p = Integer.parseInt(inputs[1]);
      S = Integer.parseInt(inputs[2]);
      satisfied.clear();
      unsatisfied.clear();
      for (int j = 3; j < inputs.length; j++) {
        int t = Integer.parseInt(inputs[j]);
        Googlers googlers = new Googlers(t, S);

        for (int k = 0; k <= 10; k++) {
          int till = k + 2 > 10 ? 10 : k + 2;
          for (int l = k; l <= till; l++) {
            googlers.set(k, l, (t - (k + l)));
          }
        }
        if (googlers.pAntiSurprising) {
          satisfied.add(googlers);
        } else {
          unsatisfied.add(googlers);
        }
      }
      int pSurprising = 0;
      if (p > 0) {
        for (Iterator<Googlers> iter = unsatisfied.iterator(); iter.hasNext(); ) {
          Googlers googlers = iter.next();
          if (googlers.pSurprising) {
            pSurprising++;
            iter.remove();
            p--;
            if (p <= 0) break;
          }
        }
      }
      if(p > 0){
        for (Iterator<Googlers> iter = unsatisfied.iterator(); iter.hasNext(); ) {
          Googlers googlers = iter.next();
          if (googlers.surprising) {
            iter.remove();
            p--;
            if (p <= 0) break;
          }
        }
      }
      if(p > 0){
        for (Iterator<Googlers> iter = satisfied.iterator(); iter.hasNext(); ) {
          Googlers googlers = iter.next();
          if (googlers.pSurprising) {
            iter.remove();
            pSurprising++;
            p--;
            if (p <= 0) break;
          }
        }
      }
      if(p > 0){
        for (Iterator<Googlers> iter = satisfied.iterator(); iter.hasNext(); ) {
          Googlers googlers = iter.next();
          if (googlers.surprising) {
            iter.remove();
            p--;
            if (p <= 0) break;
          }
        }
      }

      if(p > 0){
        writer.print("Case #" + i + ": 0");
      }else {
        writer.print("Case #" + i + ": " + (satisfied.size() + pSurprising));
      }
      writer.println();
    }
    writer.flush();
  }


}

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