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.*;

public class jam2 {

	/**
	 * @param args
	 */
	static int chuli(String in)
	{
		String[] ss = in.split(" ");
		int n = Integer.parseInt(ss[0]);
		int s = Integer.parseInt(ss[1]);
		int p = Integer.parseInt(ss[2]);

		ArrayList<Integer> ar = new ArrayList<Integer>();
		ArrayList<Integer> sy = new ArrayList<Integer>();
		ArrayList<Integer> sn = new ArrayList<Integer>();
		
		for(int i=0;i<n;i++)
			ar.add(Integer.parseInt(ss[3+i]));
		
		for(int i=0;i<n;i++)
		{
			int t = ar.get(i);
			if(t==0)
			{
				sy.add(-1);
				sn.add(0);
				
			}
			else
			{
			if(t==1)
			{
				sy.add(-1);
				sn.add(1);
				continue;
			}
			else{
			int tn = t/3;
			if(t%3==0)
			{
				sy.add(tn+1);
				sn.add(tn);
			}
			if(t%3==1)
			{
				sy.add(tn+1);
				sn.add(tn+1);
			}
			if(t%3==2)
			{
				sy.add(tn+2);
				sn.add(tn+1);
			}}
			}
		}
		
		
		int[][] map = new int[n+1][s+1];
		for(int i=0;i<=s;i++)
			map[0][i]=0;
		
		for(int ni = 1;ni <= n; ni++)
		{
			//System.out.println(ar.get(ni-1));
			map[ni][0]=map[ni-1][0];
			if(sn.get(ni-1)>=p)
			{
				map[ni][0]+=1;
			}
			//System.out.println(map[ni][0]);
			//System.out.println("---");
		}
		
		for(int ni = 1;ni<=n;ni++)
		{
			for(int si=1;si<=s;si++)
			{
				if(ar.get(ni-1)<2)
				{
					map[ni][si]=map[ni-1][si]+(sn.get(ni-1)>=p?1:0);
				}
				else
				{
				int s1 = map[ni-1][si]+(sn.get(ni-1)>=p?1:0);
				int s2 = map[ni-1][si-1]+(sy.get(ni-1)>=p?1:0);
				map[ni][si]=s1>s2?s1:s2;
				}
			}
		}
		/*
		System.out.println("###");
		for(int ni = 0;ni<=n;ni++)
		{
			for(int si=0;si<=s;si++)
			{
				System.out.print(map[ni][si]);
				System.out.print(" ");
			}
			System.out.println();
		}
		System.out.println("###");
		*/
		return map[n][s];
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try{
			/*
			System.out.println(chuli("3 1 5 15 13 11"));
			
			System.out.println(chuli("3 0 8 23 22 21"));
			
			System.out.println(chuli("2 1 1 8 0"));
			
			System.out.println(chuli("6 2 8 29 20 8 18 18 21"));
			
			*/
			File fin1 = new File("d:\\B-large.in");
	    	FileInputStream fs1 = new FileInputStream(fin1);
	    	BufferedReader br1 = new BufferedReader(new InputStreamReader(fs1));
	    	
	    	File fout6 = new File("d:\\cjamout1");
	    	FileOutputStream fos6 = new FileOutputStream(fout6);
	    	BufferedWriter wr6 = new BufferedWriter(new OutputStreamWriter(fos6));
	       
	    	String line = br1.readLine();
	    	int n = 1;
	    	line = br1.readLine();
	    	while(line!=null)
	    	{
	    	   if(!line.trim().equals(""))
	    	   {
	    		   wr6.write("Case #"+String.valueOf(n++)+": "+String.valueOf(chuli(line)));
	    	       wr6.newLine();
	    	   }
	    	   line = br1.readLine();
	    	  
			}
	    	br1.close();
	    	fs1.close();
	    	
	    	wr6.close();
	    	fos6.close();
	    	
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

}
