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.*;
import java.util.*;

/**
 * @author Chris Dziemborowicz <chris@dziemborowicz.com>
 * @version 2012.0414
 */
public class DancingWithTheGooglers
{
    public static void main(String[] args)
            throws Exception
    {
        // Get input files
        File dir = new File("/Users/Chris/Documents/UniSVN/code-jam/dancing-with-the-googlers/data");
        File[] inputFiles = dir.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name)
            {
                return name.endsWith(".in");
            }
        });

        // Learn score mappings
        learn();

        // Process each input file
        for (File inputFile : inputFiles) {
            System.out.printf("Processing \"%s\"...\n", inputFile.getName());

            String outputPath = inputFile.getPath().replaceAll("\\.in$", ".out");
            BufferedWriter writer = new BufferedWriter(new FileWriter(outputPath));

            Scanner scanner = new Scanner(inputFile);
            System.out.printf("Number of test cases: %s\n", scanner.nextLine());

            int count = 0;
            while (scanner.hasNext()) {
                String line = scanner.nextLine();
                String output = String.format("Case #%d: %d\n", ++count, process(line));

                System.out.print(output);
                writer.write(output);
            }

            writer.close();
            System.out.println("Done.\n");
        }

        // Compare to reference files (if any)
        for (File inputFile : inputFiles) {
            System.out.printf("Verifying \"%s\"...\n", inputFile.getName());

            String referencePath = inputFile.getPath().replaceAll("\\.in$", ".ref");
            String outputPath = inputFile.getPath().replaceAll("\\.in$", ".out");

            File referenceFile = new File(referencePath);
            if (referenceFile.exists()) {
                InputStream referenceStream = new FileInputStream(referencePath);
                InputStream outputStream = new FileInputStream(outputPath);

                boolean matched = true;
                int referenceRead, outputRead;
                do {
                    byte[] referenceBuffer = new byte[4096];
                    byte[] outputBuffer = new byte[4096];

                    referenceRead = referenceStream.read(referenceBuffer);
                    outputRead = outputStream.read(outputBuffer);

                    matched = referenceRead == outputRead
                            && Arrays.equals(referenceBuffer, outputBuffer);
                } while (matched && referenceRead != -1);

                if (matched) {
                    System.out.println("Verified.\n");
                } else {
                    System.out.println("*** NOT VERIFIED ***\n");
                }
            } else {
                System.out.println("No reference file found.\n");
            }
        }
    }


    private static int[] highestOrdinary = new int[31];
    private static int[] highestSurprising = new int[31];


    public static void learn()
    {
        Arrays.fill(highestOrdinary, -1);
        Arrays.fill(highestSurprising, -1);

        for (int i = 0; i <= 10; i++) {
            for (int j = i; j <= i + 2 && j <= 10; j++) {
                for (int k = j; k <= i + 2 && k <= 10; k++) {
                    int score = i + j + k;
                    if (k == i + 2) {
                        if (k > highestSurprising[score]) {
                            highestSurprising[score] = k;
                        }
                    } else {
                        if (k > highestOrdinary[score]) {
                            highestOrdinary[score] = k;
                        }
                    }
                }
            }
        }
    }


    public static int process(String line)
    {
        // Parse input
        Scanner scanner = new Scanner(line);
        int num = scanner.nextInt();
        int numSurprising = scanner.nextInt();
        int p = scanner.nextInt();
        int[] scores = new int[num];
        for (int i = 0; i < num; i++) {
            scores[i] = scanner.nextInt();
        }

        // Find surprising scores
        int count = 0;
        for (int score : scores) {
            if (highestOrdinary[score] >= p) {
                count++;
            } else if (numSurprising > 0 && highestSurprising[score] >= p) {
                numSurprising--;
                count++;
            }
        }
        return count;
    }
}