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 hu.herba.codejam.cj2012.qualification;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;

import hu.herba.codejam.AbstractCodeJamBase;

/**
 * Dancing with the Googlers
 * 
 * @author csorbazoli
 */
public class ProblemB extends AbstractCodeJamBase {

    public static void main(String[] args) {
	new ProblemB(args);
    }

    int T; // number of test case

    public ProblemB(String[] args) {
	super(args, AbstractCodeJamBase.READER_TYPE);
    }

    /*
     * (non-Javadoc)
     * 
     * @see hu.herba.codejam.AbstractCodeJamBase#process(java.io.BufferedReader,
     * java.io.PrintWriter)
     */
    @Override
    protected void process(BufferedReader reader, PrintWriter pw) throws IOException, IllegalArgumentException {
	// The first line of the input gives the number of test cases, T. T test
	// cases follow, one per line.
	this.T = this.readInt(reader, "Number of cases");
	int[] items;
	int result = 0;
	int N, S, p;
	int surp, smallest, cur, diff;
	for (int i = 1; i <= this.T; i++) {
	    items = this.readIntArray(reader, "N, S, p and N integers");
	    // The first integer will be N, the number of Googlers,
	    // and the second integer will be S, the number of surprising
	    // triplets of scores.
	    // The third integer will be p, as described above.
	    // Next will be N integers ti: the total points of the Googlers.
	    if ((items.length > 0) && (items.length == 3 + items[0])) {
		// * TEST */System.out.println("Case #" + i + ": input = " +
		// Arrays.toString(items));
		N = items[0];
		S = items[1];
		p = items[2];
		// For each test case, output one line containing "Case #x: y",
		// where x is the case number (starting from 1) and y is the
		// maximum number of Googlers who could have had a best result
		// of greater than or equal to p.
		surp = result = 0;
		for (int j = 0; j < N; j++) {
		    cur = items[3 + j];
		    if (cur >= p) {
			// smallest result
			smallest = (cur - p) / 2;
			diff = p - smallest;
			if (diff <= 2) {
			    if (diff == 2) { // only when suprising
				surp++;
				// * TEST */System.out.println("	" + cur +
				// " -> SUPP");
			    } else { // even if not surprising
				// * TEST */System.out.println("	" + cur +
				// " -> MAX");
				result++;
			    }
			} // else not possible
		    }
		}
		// at most S googlers may have p points amoung surp
		// * TEST */System.out.println("	result = " + result + " + " +
		// Math.min(surp, S));
		result += Math.min(surp, S);
		pw.println("Case #" + i + ": " + result);
	    } else {
		System.out.println("Test case " + i + " INVALID: input line should contain N, S, p and N integers" + Arrays.toString(items));
	    }
	}
    }
}
