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 google.code.jam;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

public class DancingWithTheGooglers {

	final static String fileNameIn = "B-large.in";
	final static String fileNameOut = "B-large.out";

	private static int solve(int S, int p, List<Integer> t) {
		int count = 0;
		for (int i = 0; i < t.size(); i++) {
			int bestResultNotSurprising = getBestResultNotSurprising(t.get(i));
			int bestResultSurprising = getBestResultSurprising(t.get(i));
			if (bestResultNotSurprising >= p) {
				count++;
			} else if (bestResultSurprising >= p && S > 0) {
				count++;
				S--;
			}
		}
		return count;
	}

	private static int getBestResultNotSurprising(int n) {
		return getBestResult(n, false);
	}

	private static int getBestResultSurprising(int n) {
		return getBestResult(n, true);
	}

	private static int getBestResult(int n, boolean surprising) {
		int average = (int) Math.floor(n / 3);
		int residue = n % 3;
		if (n == 0)
			return 0;
		if (surprising && residue == 0)
			return average + 1;
		if (surprising && residue == 1)
			return average + 1;
		if (surprising && residue == 2)
			return average + 2;
		if (!surprising && residue == 0)
			return average;
		if (!surprising && residue == 1)
			return average + 1;
		if (!surprising && residue == 2)
			return average + 1;
		return average;
	}

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader(fileNameIn));
		BufferedWriter out = new BufferedWriter(new FileWriter(fileNameOut));
		int testCases = Integer.parseInt(in.readLine());
		for (int i = 0; i < testCases; i++) {
			String[] elements = in.readLine().split(
					new Character((char) 32).toString());
			List<Integer> values = new ArrayList<Integer>();
			for (String v : elements) {
				values.add(Integer.valueOf(v));
			}
			ListIterator<Integer> iterator = values.listIterator();
			int N = iterator.next();
			int S = iterator.next();
			int p = iterator.next();
			List<Integer> t = values.subList(values.size() - N, values.size());
			out.write(String.format("Case #%s: %s\n", i + 1, solve(S, p, t)));
		}
		in.close();
		out.close();
	}

}
