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

import codejam.CodeJam;

public class Main extends CodeJam {

	public static void main(String[] args) {
		new Main() {
			// Override the input file with the following: e.g. if the value is "large", then read "A-large.in" instead of the default
			//@SuppressWarnings("unused")
			//public static final String OVERRIDE_INPUT_FILE = "small-attempt0"; // "large";
		};
	}

	// --------------------------------------------------------------------------------------------------------------

	private static void max(int[] bestScoreForTot, int tot, int bestTot) {
		if (bestTot <= 10)
			bestScoreForTot[tot] = Math.max(bestScoreForTot[tot], bestTot);
	}

	@Override
	public void solve() {

		int[] bestScoreForTot_surprising = new int[31];
		int[] bestScoreForTot_nonSurprising = new int[31];
		for (int a = 1; a <= 10; a++) {
			max(bestScoreForTot_nonSurprising, (a + 0) + (a + 0) + (a + 0), a);
			max(bestScoreForTot_nonSurprising, (a + 0) + (a + 0) + (a + 1), a + 1);
			max(bestScoreForTot_nonSurprising, (a + 0) + (a + 1) + (a + 1), a + 1);
			max(bestScoreForTot_surprising, (a + 0) + (a + 0) + (a + 2), a + 2);
			max(bestScoreForTot_surprising, (a + 0) + (a + 1) + (a + 2), a + 2);
			max(bestScoreForTot_surprising, (a + 0) + (a + 2) + (a + 2), a + 2);
		}
		//		for (int i = 3; i <= 30; i++) 
		//			System.out.println(i + " " + bestScoreForTot_surprising[i] + " " + bestScoreForTot_nonSurprising[i]);
		//		3 0 1
		//		4 0 2
		//		5 3 2
		//		6 3 2
		//		7 3 3
		//		8 4 3
		//		9 4 3
		//		10 4 4
		//		11 5 4
		//		12 5 4
		//		13 5 5
		//		14 6 5
		//		15 6 5
		//		16 6 6
		//		17 7 6
		//		18 7 6
		//		19 7 7
		//		20 8 7
		//		21 8 7
		//		22 8 8
		//		23 9 8
		//		24 9 8
		//		25 9 9
		//		26 10 9
		//		27 10 9
		//		28 10 10
		//		29 0 10
		//		30 0 10

		int T = readInt();
		for (int t = 0; t < T; t++) {
			int N = readInt();
			int S = readInt();
			int p = readInt();
			
			int numGooglersWithMinScore = 0;
			for (int i = 0; i < N; i++) {
				int totScore = readInt();
				int bestScoreSurprising = bestScoreForTot_surprising[totScore];
				int bestScoreNonSurprising = bestScoreForTot_nonSurprising[totScore];
				if (bestScoreNonSurprising >= p) {
					numGooglersWithMinScore++;
				} else if (bestScoreSurprising < p) {
					// skip
				} else if (bestScoreSurprising >= p) {
					if (S > 0) {
						S--;
						numGooglersWithMinScore++;
					}
				}
			}
			
			writeCaseNumThenLine(numGooglersWithMinScore);
		}
	}
}
