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


}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dancingwiththegooglers;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

/**
 *
 * @author arjun
 */
public class DancingWiththeGooglers {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException {
        PrintStream out = new PrintStream(new FileOutputStream("output.txt"));
        System.setOut(out);
        parseAndTranslate();
    }

    private static void parseAndTranslate() {
        try {
            // Open the file that is the first 
            // command line parameter
            FileInputStream fstream = new FileInputStream("B-large.in");
            // Get the object of DataInputStream
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strLine = br.readLine();
            if (null != strLine) {
                int count = new Integer(strLine);
                //Read File Line By Line
                int lineNo = 0;
                while ((strLine = br.readLine()) != null) {
                    lineNo++;
                    doOp(strLine, lineNo);
                }
                //Close the input stream
            }
            in.close();
        } catch (Exception e) {//Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }
    }

    private static void doOp(String strLine, int lineNo) {

        StringTokenizer st = new StringTokenizer(strLine);

        String temp = st.nextToken();
        int noOfGooglers = new Integer(temp);

        temp = st.nextToken();
        int surprisingTriplets = new Integer(temp);

        temp = st.nextToken();
        int bestScore = new Integer(temp);
        //System.out.println("Goog: " + noOfGooglers + " surp: " + surprisingTriplets
          //    + " bestScore: " + bestScore + " ");
        int nthNo = 0;
        Map<Integer, List<Integer>> iSet = new HashMap<Integer, List<Integer>>();
        while (st.hasMoreTokens()) {
            nthNo++;
            String pts = st.nextElement().toString();
            int pt = new Integer(pts);
            //System.out.print(" " + pt);
            boolean SurpUsed = compute(pt, bestScore, surprisingTriplets, iSet, nthNo);
            if (SurpUsed) {
                surprisingTriplets -= 1;
            }
        }

        int topScores = 0;
        for (Integer pointNo : iSet.keySet()) {              
            List<Integer> points = iSet.get(pointNo);
            //System.out.print("\nNo: " + pointNo + ", Scores: ");
            boolean topScoreFoundAlready = false;
            for (Integer p : points) {
                if (p >= bestScore && !topScoreFoundAlready) {
                    topScores++;
                    topScoreFoundAlready = true;
                }
                //System.out.print(" " + p);
            }
            //System.out.println();
        }
        System.out.println("Case #" + lineNo + ": " + topScores);
    }

    private static boolean compute(int pt, int bestScore, int surprisingTriplets,
            Map<Integer, List<Integer>> iSet, int nthNo) {
        List<Integer> points = new ArrayList<Integer>();
        boolean surpUsed = false;

        int no1 = 0, no2 = 0, no3 = 0;
        int mean = Math.round(pt / 3);
        int rem = pt % 3;

        if (0 == rem) {
            if (mean < bestScore) {
                if (surprisingTriplets > 0 && (mean + 1) >= bestScore 
                        && (mean - 1) >= 0 && (mean + 1) <= 10) {
                    surpUsed = true;
                    no1 = mean;
                    no2 = mean + 1;
                    no3 = mean - 1;
                } else {
                    no1 = mean;
                    no2 = mean;
                    no3 = mean;
                }
            } else {
                no1 = mean;
                no2 = mean;
                no3 = mean;
            }
        } else if (1 == rem) {
            no1 = mean + 1;
            no2 = mean;
            no3 = mean;
        } else if (2 == rem) {
            if ((mean + 1) < bestScore) {
                if (surprisingTriplets > 0 && (mean + 2) >= bestScore
                        && (mean + 2) <= 10) {
                    surpUsed = true;
                    no1 = mean + 2;
                    no2 = mean;
                    no3 = mean;
                } else {
                    no1 = mean + 1;
                    no2 = mean + 1;
                    no3 = mean;
                }
            } else {
                no1 = mean + 1;
                no2 = mean + 1;
                no3 = mean;
            }
        }


        points.add(no1);
        points.add(no2);
        points.add(no3);
        iSet.put(nthNo, points);
        return surpUsed;
    }
}
