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.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class GoogleDancers {
   private static final List<Case> cases = new ArrayList<Case>();

   public static void main(String[] args) throws IOException {
      // sanityCheck();
      readInFile("src/resources/dancers/B-large.in");
      FileWriter fstream = new FileWriter("src/resources/dancers/B-large.out");
      BufferedWriter out = new BufferedWriter(fstream);

      for (int i = 0; i < cases.size(); i++) {
         String msg = "Case #" + (i + 1) + ": " + cases.get(i).getResult() + "\n";
         out.write(msg);
         System.out.print(msg);
      }
      out.close();
   }

   protected static void readInFile(String path) throws NumberFormatException, IOException {
      DataInputStream in = new DataInputStream(new FileInputStream(path));
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      int lines = Integer.parseInt(br.readLine());
      for (int i = 0; i < lines; i++) {
         cases.add(new Case(br.readLine()));
      }
      in.close();
   }
}

class Case {
   protected int             N;
   protected int             S;
   protected int             p;
   protected TreeSet<Dancer> dancers = new TreeSet<Dancer>();

   public Case(String line) {
      StringTokenizer tokenizer = new StringTokenizer(line);
      N = Integer.parseInt(tokenizer.nextToken());
      S = Integer.parseInt(tokenizer.nextToken());
      p = Integer.parseInt(tokenizer.nextToken());
      for (int i = 0; i < N; i++) {
         dancers.add(new Dancer(Integer.parseInt(tokenizer.nextToken())));
      }
   }

   public int getResult() {
      System.out.println(this);
      int ctr = 0;
      for (Dancer d : dancers) {
         if (d.expected.max() >= p) {
            ctr += 1;
         } else if ((d.surprising != null) && (d.surprising.max() >= p) && (d.surprising.max() >= d.expected.max()) && (S > 0)) {
            ctr += 1;
            S -= 1;
         }
         System.out.println(d);
      }
      return ctr;
   }

   @Override
   public String toString() {
      return "N=" + N + ", S=" + S + ", p=" + p;
   }
}

class Dancer implements Comparable<Dancer> {
   Triplet expected;
   Triplet surprising;

   protected Dancer(int score) {
      expected = Triplet.expected(score);
      surprising = Triplet.surprising(score);
   }

   protected int max() {
      if (surprising == null) {
         return expected.max();
      } else {
         return Math.max(expected.max(), surprising.max());
      }
   }

   @Override
   public int compareTo(Dancer arg0) {
      if (max() < arg0.max()) {
         return 1;
      } else {
         return -1;
      }
   }

   @Override
   public String toString() {
      return expected.toString() + ", " + surprising;
   }
}

/**
 * "Note: this class has a natural ordering that is inconsistent with equals."
 */
class Triplet implements Comparable<Triplet> {
   protected boolean isSurprising = false;
   protected int     t1, t2, t3;

   protected Triplet(int t1, int t2, int t3) {
      this.t1 = t1;
      this.t2 = t2;
      this.t3 = t3;
      isSurprising = (Math.abs(t1 - t2) >= 2) || (Math.abs(t2 - t3) >= 2) || (Math.abs(t1 - t3) >= 2);
   }

   protected static Triplet expected(int score) {
      if (score == 0) {
         return new Triplet(0, 0, 0);
      } else if (score % 3 == 0) {
         return new Triplet(score / 3, score / 3, score / 3);
      } else if (score % 3 == 1) {
         return new Triplet(score / 3, score / 3, score / 3 + 1);
      } else {
         return new Triplet(score / 3, score / 3 + 1, score / 3 + 1);
      }
   }

   protected static Triplet surprising(int score) {
      if (score < 2) {
         return null;
      } else if (score % 3 == 0) {
         return new Triplet(score / 3 - 1, score / 3, score / 3 + 1);
      } else if (score % 3 == 1) {
         return new Triplet(score / 3 - 1, score / 3 + 1, score / 3 + 1);
      } else {
         return new Triplet(score / 3, score / 3, score / 3 + 2);
      }
   }

   public int max() {
      return Math.max(t1, Math.max(t2, t3));
   }

   @Override
   public int compareTo(Triplet arg0) {
      if (max() < arg0.max()) {
         return 1;
      } else {
         return -1;
      }
   }

   @Override
   public String toString() {
      return String.format("(%s, %s, %s) %s [Total=%s]", t1, t2, t3, ((isSurprising) ? "*" : " "), (t1 + t2 + t3));
   }
}