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.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;

public class Dancers{   
  public static ArrayList<Triplet> scores;
  
  public static void main(String arg[]){
    System.out.print("Enter the file path of the input file : ");
    String path = new Scanner(System.in).nextLine();
    String ANS ="", output="", test;
    int diff;
    
    try{
      Scanner read = new Scanner(new File(path));
      int testCases =  Integer.parseInt(read.nextLine());
      int cn=0; String tongue; 
      while(cn++<testCases){
        test  = read.nextLine();
        
        output = "Case #"+cn+": "+ solve(test);//WRITE ANS TO DIFFERENT FILE 
        ANS += output +" \n";
        System.out.println(ANS);
      }
      writeToFile("dancers.out",ANS);
    }
    catch(FileNotFoundException e){//if file is not found
      System.err.println("data file \'"+path+"\' was not found\nPress <enter> to exit...");
      (new Scanner(System.in)).nextLine();
      System.exit(1);
    }
  }
  
  public static void writeToFile(String file, String text){
    PrintStream out = null;
    try {
      out = new PrintStream(new FileOutputStream(file));
      out.print(text);
    }
    catch(Exception e){}
    finally {
      if (out != null) out.close();
    }   
  }
  
  public static int solve(String test){
    String temp[] = test.split(" ");
    ArrayList<Triplet> tempList = new ArrayList<Triplet>();
    Triplet[] scores;
    int dancerNo, surpriseNo, bestResult;
      
    dancerNo = Integer.parseInt(temp[0]);
    surpriseNo = Integer.parseInt(temp[1]);
    bestResult = Integer.parseInt(temp[2]);
    int counter = 0;
    
    while(counter < dancerNo){
      tempList.add(new Triplet(temp[3+counter])); 
      counter++;
    }
    
    scores = tempList.toArray(new Triplet[tempList.size()]);
    
    
    Arrays.sort(scores);
    
    scores = doTheSurprises(scores,surpriseNo, bestResult);  
    
    System.out.println(Arrays.toString(scores));
    
    return count(scores, bestResult);
  }
  
  public static Triplet[] doTheSurprises(Triplet sc[], int surprise, int max){
    Triplet temp;
    int sNo=0;
    for(int i=sc.length-1; i>=0; i--){
      if(sNo==surprise){
        break;
      }
      
      if(sc[i].scores[2]<max){
        if(sc[i].doSurprise()){
          sNo++;
        }
      }
    }    
    return sc;
  }
  
  public static int count(Triplet sc[], int max){
    int temp=0;
    for(int i=0; i<sc.length; i++){
      if(sc[i].scores[2]>=max){
        temp++;
      }
    }
    return temp;}
}

class Triplet implements Comparable<Triplet>{
  public int scores[] = new int[3];
  public Triplet(int x, int y, int z){
    scores[0]=x;
    scores[1]=y;
    scores[2]=z;
  }
  
  public Triplet(String x){setThrees(Integer.parseInt(x));}
  
  public Triplet(int x){setThrees(x);}
  
  public void setThrees(int numb){
    this.scores[0] =numb/3;
    this.scores[1] = (numb-scores[0])/2;
    this.scores[2] = numb - scores[0] - scores[1];
  } 
  
  public int compareTo(Triplet x){
    if(scores[2]<x.scores[2]){
      return -1;
    }
    else if(scores[2]>x.scores[2]){
      return 1;
    }
    else{
      return 0;
    }
    
  }
  
  public boolean doSurprise(){
    int s1 = scores[1], s2 = scores[2];
    
    if(s1 == s2){
      s1--; s2++;
      if(s1>=0 && s2<=10){
        scores[1] = s1;
        scores[2] = s2;
        return true;
      }
    }
    return false;
  }
  
  public String toString(){
    return Arrays.toString(scores);
  }
}
