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();
  }


}

package gcj.qualifier;
/**
 * @(#)ProbB.java
 *
 *
 * @author 
 * @version 1.00 2011/5/9
 */

import java.io.*;
import java.math.*;
import java.lang.*;
import java.util.*;

import static java.lang.System.*;
import static java.lang.Integer.*;
public class ProbB
{

	public FileReader fr;
	public BufferedReader br;

	
    public ProbB(String file, String output)
    {
    	if (output!=null)
			setOut(output);

    	try
    	{
   	    	fr=new FileReader(file);
 	   		br=new BufferedReader(fr);
 	   		
    		int caseNo=parseInt(br.readLine());
    		//out.println(caseNo);
    		for (int i=0; i<caseNo; i++)
    		{
    			String caseAnswer=runCase();
    			out.println("Case #"+ (i+1) + ": " +caseAnswer);
    		}
    		
    	}
    	catch (IOException e)
    	{
    	}

    }

    public void setOut(String output)
    {
		try
    	{
			System.setOut(new PrintStream(output));
		}
    	catch (FileNotFoundException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
		}    	
    }
    
    public String runCase() throws IOException
    {
    	String ss=br.readLine();
    	StringTokenizer st=new StringTokenizer(ss);
    	int t=Integer.parseInt(st.nextToken());
    	int s=Integer.parseInt(st.nextToken());
    	int p=Integer.parseInt(st.nextToken());
    	int [] tt=new int[t];
    	int test=4;
    	if (p>2)
    		test=(p-2)*3;
 //   	out.println();
 //   	out.println(test);
    	int num=0;
    	//double test=((double)p-((double)2/3));

    	int div; int mod;
    	for (int i=0; i<t; i++)
    	{
    		tt[i]=Integer.parseInt(st.nextToken());
    		div=tt[i]/3;mod=tt[i]%3;
    		if (tt[i]>=p)
    		{
        		if (div>=p-2)
        		{
        			if (div>=p || (div==(p-1)&&(mod==2||mod==1)))
        			{
        				num++;
        			}
        			else if (s>0)
        			{
        				if ((div==(p-2)&&mod==2)||(div==(p-1)&&mod==0))
        				{
        					s--;
//        					out.print("*");
        					num++;

        				}
        				
        				
        			}
        			else continue;

/*
            		out.print(tt[i]);
            		out.print(" : ");
            		out.print(tt[i]/3);
            		out.print(" : ");
            		out.print(tt[i]%3);
            		out.print(" : ");
            		out.println();    			    				
  */
        		}
    		}

//    		out.println(p+":::"+tt[i]+":"+tt[i]/3+":"+tt[i]%p);

    		
      		//out.println(tt[i]);
    	}

	
    		//out.println(num);

        	return new Integer(num).toString();
    }
    
    public static void main(String [] args)
    {
    	ProbB gjct=new ProbB("C:/JavaPgms/workspace/codejam/2012/in/qualifier/B-large.in", "C:/JavaPgms/workspace/codejam/2012/out/qualifier/B.out");
    }
    
    
    
    
}