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


public class B {

	public void func(){
		
		Scanner in=null;
		try {
			in = new Scanner(new File("input.txt"));
		} catch (FileNotFoundException e) {			
			e.printStackTrace();
		}
		int no = in.nextInt();		
		for(int i=0;i<no;++i){
			int ng = in.nextInt();
			int sp = in.nextInt();
			int min = in.nextInt();
			int res = 0;
			int ss = 0;
			int k =3;
			int v = 0;
			int flag = 0;
			int[][] intArr = new int[ng][4]; 
			for(int j=0;j<ng;++j){
				int score = in.nextInt();
				flag = 0;
				v=0;
				k=3;
				while(v<3){
					intArr[j][v] = score/k;
					score -= intArr[j][v];
					if((intArr[j][v] >= min) && flag == 0){
						res++;
						intArr[j][3] = 1;
						++flag;
					}
					--k;
					++v;					
				}
				if(Math.abs((intArr[j][0]-intArr[j][1])) == 2 || Math.abs((intArr[j][1]-intArr[j][2])) == 2 || Math.abs((intArr[j][2]-intArr[j][0])) == 2 ){
					++ss;
				}
			}
			if((res <  ng) && (ss < sp)){
				for(int j=0;j<ng;++j){
					if(intArr[j][3] == 0 && (intArr[j][0]+intArr[j][1]+intArr[j][2] != 0)){
						if(Math.abs(intArr[j][0]-intArr[j][1]) < 1){
							if(j==ng-1){
								intArr[j][0]--;
								intArr[j][1]++;
								if(intArr[j][0] >= min || intArr[j][1]>= min) ++res;
								++ss;
							}else{
								if(intArr[j][0]-1 >= min || intArr[j][1]+1 >= min){
									intArr[j][0]--;
									intArr[j][1]++;
									++res;
									++ss;
								}
							}
							///continue;
						}else if(Math.abs(intArr[j][1]-intArr[j][2]) < 1){
							if(j==ng-1){
								intArr[j][1]--;
								intArr[j][2]++;
								if(intArr[j][1] >= min || intArr[j][2]>= min) ++res;
								++ss;
							}else{
								if(intArr[j][1]-1 >= min || intArr[j][2]+1 >= min){
									intArr[j][1]--;
									intArr[j][2]++;
									++res;
									++ss;
								}
							}
						}else if(Math.abs(intArr[j][2]-intArr[j][0]) < 1){
							if(j==ng-1){
								intArr[j][2]--;
								intArr[j][0]++;
								if(intArr[j][0] >= min || intArr[j][2]>=min) ++res;
								++ss;
							}else{
								if(intArr[j][2]-1 >= min || intArr[j][0]+1 >= min){
									intArr[j][2]--;
									intArr[j][0]++;
									++res;
									++ss;
								}
							}
						}
						if(ss>=sp){
							break;
						}
					}
				}
			}
			System.out.println("Case #"+(i+1)+": "+res);
		}
	}
	
	
	public static void main(String[] args) {
		B b = new B();
		b.func();
	}

}
