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

import java.util.ArrayList;

/**
 * String splitter, this fixes the problem that String.split() has of losing the last token if it's empty. It also uses
 * CharSequences rather than allocating new String objects.
 */
public class Split {

	/**
	 * String splitter, this fixes the problem that String.split() has of losing the last token if it's empty. It also uses
	 * CharSequences rather than allocating new String objects.
	 */
	public static ArrayList<CharSequence> splitAsList(String str, String sep) {
		int strLen = str.length();
		int sepLen = sep.length();
		assert sepLen > 0;

		ArrayList<CharSequence> parts = new ArrayList<CharSequence>();
		for (int curr = 0; curr <= strLen;) {
			// Look for next token
			int next = str.indexOf(sep, curr);
			// Read to end if none
			if (next < 0)
				next = strLen;
			// Add next token
			parts.add(str.subSequence(curr, next));
			// Move to end of separator, or past end of string if we're at the end
			// (by stopping when curr <= strLen rather than when curr < strLen,
			// we avoid the problem inherent in the Java standard libraries of
			// dropping the last field if it's empty; fortunately
			// str.indexOf(sep, curr) still works when curr == str.length()
			// without throwing an index out of range exception).
			curr = next + sepLen;
		}
		return parts;
	}

	public static CharSequence[] splitAsArray(String str, String sep) {
		ArrayList<CharSequence> list = splitAsList(str, sep);
		CharSequence[] arr = new CharSequence[list.size()];
		list.toArray(arr);
		return arr;
	}

	public static ArrayList<String> splitAsListOfString(String str, String sep) {
		ArrayList<CharSequence> list = splitAsList(str, sep);
		ArrayList<String> listOfString = new ArrayList<String>(list.size());
		for (CharSequence cs : list)
			listOfString.add(cs.toString());
		return listOfString;
	}

	/** For compatibility only, slower because it creates new String objects for each CharSequence */
	public static String[] split(String str, String sep) {
		ArrayList<CharSequence> list = splitAsList(str, sep);
		String[] arr = new String[list.size()];
		for (int i = 0; i < list.size(); i++)
			arr[i] = list.get(i).toString();
		return arr;
	}

	//	public static void main(String[] args) {
	//		System.out.println(splitAsList("", "\t"));
	//		System.out.println(splitAsList("\t", "\t"));
	//		System.out.println(splitAsList("a\t", "\t"));
	//		System.out.println(splitAsList("\ta", "\t"));
	//		System.out.println(splitAsList("\ta\t", "\t"));
	//		System.out.println(splitAsList("a\tb", "\t"));
	//		System.out.println(splitAsList("a\tb\t", "\t"));
	//		System.out.println(splitAsList("\ta\tb", "\t"));
	//		System.out.println(splitAsList("", "SEP"));
	//		System.out.println(splitAsList("SEP", "SEP"));
	//		System.out.println(splitAsList("aSEP", "SEP"));
	//		System.out.println(splitAsList("SEPaSEPb", "SEP"));
	//		System.out.println(splitAsList("aSEPbSEP", "SEP"));
	//	}

}
