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.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;


public class QuestionB {
	
	public static void doPuzzle() {

		try {
	
			File questionfile = new File("B.in");
			BufferedReader questionreader = new BufferedReader(new FileReader(questionfile));
	
			File answerfile = new File("B.out");
			PrintWriter answerwriter = new PrintWriter(new BufferedWriter(new FileWriter(answerfile)));

			String[] params = null;
			String question = questionreader.readLine();
			int T = Integer.parseInt(question);
			
			int[][] table = makeTable();
			
			for (int i = 0; i < T; i++) {
				question = questionreader.readLine();
				params = question.split(" ");
				int N = Integer.parseInt(params[0]);
				int S = Integer.parseInt(params[1]);
				int p = Integer.parseInt(params[2]);
				int[] t = new int[N];
				for (int j = 0; j < N; j++) t[j] = Integer.parseInt(params[3+j]);
				answerwriter.println("Case #" + (i+1) + ": " + analyze(table, N, S, p, t));
			}
			
			answerwriter.close();
			questionreader.close();
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return;
		} catch (IOException e) {
			e.printStackTrace();
			return;
		}
	}

	private static int[][] makeTable() {
		int[][] scoreTable = new int[31][11];
		for (int i = 0; i < 31; i++) {
			if (i == 0) {
				for (int j = 0; j < 1; j++) scoreTable[i][j] = 2;
				for (int j = 1; j < 11; j++) scoreTable[i][j] = 0;
				continue;
			}
			if (i == 1) {
				for (int j = 0; j < 2; j++) scoreTable[i][j] = 2;
				for (int j = 2; j < 11; j++) scoreTable[i][j] = 0;
				continue;
			}
			if (i >= 28) {
				for (int j = 0; j < 11; j++) scoreTable[i][j] = 2;
				continue;
			}
			int shou = i / 3;
			int amari = i % 3;
			switch (amari) {
			case 0:
				for (int j = 0; j < shou+1; j++) scoreTable[i][j] = 2;
				scoreTable[i][shou+1] = 1;
				for (int j = shou+2; j < 11; j++) scoreTable[i][j] = 0;
				break;
			case 1:
				for (int j = 0; j < shou+2; j++) scoreTable[i][j] = 2;
				for (int j = shou+2; j < 11; j++) scoreTable[i][j] = 0;
				break;
			case 2:
				for (int j = 0; j < shou+2; j++) scoreTable[i][j] = 2;
				scoreTable[i][shou+2] = 1;
				for (int j = shou+3; j < 11; j++) scoreTable[i][j] = 0;
				break;
			}
			
		}
		
		return scoreTable;
	}
	
	private static int analyze(int[][] table, int N, int S, int p, int[] t) {
		int[] count = new int[3];
		for (int i = 0; i < t.length; i++) {
			count[table[t[i]][p]]++;
		}
		int border = (count[1] < S) ? count[1] : S;
		
		return count[2] + border;
	}
}

