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


}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Dancing {

    static int[] max_surprising = new int[31];
    static int[] max_no_surprising = new int[31];

    public static void main(String[] args) throws IOException {

        max_surprising[0] = 0;
        max_no_surprising[0] = 0;
        max_surprising[1] = 0;
        max_no_surprising[1] = 0;
        for (int i = 2; i < 29; i++) {

            int remainder = i % 3;
            int quotient = i / 3;
            if (remainder == 0) {
                max_no_surprising[i] = quotient;
                max_surprising[i] = quotient + 1;
            } else if (remainder == 1) {
                max_no_surprising[i] = quotient + 1;
                max_surprising[i] = quotient + 1;
            } else {
                max_no_surprising[i] = quotient + 1;
                max_surprising[i] = quotient + 2;
            }
        }
        max_no_surprising[29] = 10;
        max_surprising[29] = 10;
        max_no_surprising[30] = 10;
        max_surprising[30] = 10;

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int cases = Integer.parseInt(in.readLine());
        for (int i = 0; i < cases; i++) {
            String[] inp = in.readLine().split(" ");
            int surprisesLeft = Integer.parseInt(inp[1]);
            int target = Integer.parseInt(inp[2]);
            String[] scores = new String[inp.length - 3];
            for(int j = 0; j < scores.length; j++)
                scores[j] = inp[j+3];
             int answer = calculate(scores, surprisesLeft, target);
             System.out.println("Case #" + (i+1) + ": " + answer);

        }



    }

    public static int calculate(String[] scoresRemaining, int surprisesLeft, int target) {
        int count = 0;

        if (scoresRemaining.length == surprisesLeft) {
            for (int i = 0; i < scoresRemaining.length; i++) {
                if (max_surprising[Integer.parseInt(scoresRemaining[i])] >= target) {
                    count++;
                }
            }
            return count;
        } else if (surprisesLeft == 0) {

            for (int i = 0; i < scoresRemaining.length; i++) {
                if (max_no_surprising[Integer.parseInt(scoresRemaining[i])] >= target) {
                    count++;
                }
            }
            return count;

        } else {
            int score = Integer.parseInt(scoresRemaining[0]);
            String[] temp = new String[scoresRemaining.length - 1];
            for (int i = 0; i < temp.length; i++) {
                temp[i] = scoresRemaining[i + 1];
            }
            if (max_no_surprising[score] >= target) {
                return 1 + calculate(temp, surprisesLeft, target);
            } else if (max_surprising[score] >= target) {
                return 1 + calculate(temp, surprisesLeft - 1, target);
            } else {
                return calculate(temp, surprisesLeft, target);
            }

        }
    }
}
