import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;


public class B {
	static int[][] memo;
	static int[] nums;
	static int p;
	public static void main(String[] args)throws IOException
	{
		Scanner br=new Scanner(new File("B-small-attempt0.in"));
		PrintWriter out=new PrintWriter(new File("b.out"));
		int cases=br.nextInt();
		for(int c=1;c<=cases;c++)
		{
			int n=br.nextInt(),s=br.nextInt();
			p=br.nextInt();
			nums=new int[n];
			for(int i=0;i<n;i++)
				nums[i]=br.nextInt();
			memo=new int[n][s+1];
			for(int[] a:memo)
				Arrays.fill(a,-1);
			out.printf("Case #%d: %d\n",c,go(0,s));
		}
		out.close();
	}
	public static int go(int index,int s)
	{
		if(index>=nums.length)
			return 0;
		if(memo[index][s]!=-1)
			return memo[index][s];
		int best=0;
		for(int i=0;i<=10;i++)
		{
			int max=i;
			for(int j=0;j<=10;j++)
			{	
				if(Math.abs(i-j)>2)
					continue;
				max=Math.max(i,j);
				thisone:
				for(int k=0;k<=10;k++)
				{
					int ret=0;
					if(Math.abs(i-k)>2||Math.abs(j-k)>2)
						continue;
					max=Math.max(max,k);
					int count=0;
					if(Math.abs(i-k)==2)
						count++;
					if(Math.abs(i-j)==2)
						count++;
					if(Math.abs(j-k)==2)
						count++;
					if(i+j+k==nums[index])
					{
						boolean surp=(count>=1);
						if(surp&&s>0)
						{
							if(max>=p)
								ret++;
							ret+=go(index+1,s-1);
						}
						else if(!surp)
						{
							if(max>=p)
								ret++;
							ret+=go(index+1,s);
						}
						best=Math.max(best,ret);
					}
					else if(i+j+k>nums[index])
						break thisone;
				}
			}
		}
		return memo[index][s]=best;
	}
}

package com.codejam.two12.GooglerDance;

import java.util.ArrayList;
import java.util.Arrays;

import com.jp.common.Puzzle;

public class GooglerDance implements Puzzle{

  private int numberOfGooglers;
  private int surprisingTriplets;
  private int parValue;
  private int[] totalPointArray;
  private int currentNumberOfSurprises;
  private ArrayList<Integer> ResultList;
  
  @Override
  public String[] solve(String[] dataSet) {
    // TODO Auto-generated method stub
    ResultList = new ArrayList<Integer>();
    processInput( dataSet);
    calculateResult();
    
    String result[] = new String[1];  
    result[0] = String.valueOf(ResultList.size());
    return result;
  }
  
  public void processInput(String[] dataSet){
    String data[] = dataSet[0].split(" ");
    numberOfGooglers = Integer.parseInt(data[0]);
    surprisingTriplets = Integer.parseInt(data[1]);
    parValue = Integer.parseInt(data[2]);
    
    totalPointArray = new int[numberOfGooglers];
    
    for(int i = 0; i < totalPointArray.length; i++){
      totalPointArray[i] = Integer.parseInt(data[ 3 + i]);
    }
    
    Arrays.sort(totalPointArray);
    
   }
  
  public void calculateResult(){
    
    for (int i = 0; i < totalPointArray.length; i++){
      int total = totalPointArray[i];
      int remainder = total / 3;
      int quotient = total % 3;
      
      int diff = parValue - remainder;
      
      // This cant be part of result. so skip and continue
      if(diff > 2 || (total == 0 && parValue != 0) ){
        continue;
      }
      else if(diff <= 0 ){
        ResultList.add(total);
        continue;
      }
      
      if(diff == 1 && quotient == 0 && currentNumberOfSurprises < surprisingTriplets){
        ++ currentNumberOfSurprises;
        ResultList.add(total);
      }
      else if(diff == 1 && quotient == 1 ){
        if(currentNumberOfSurprises < surprisingTriplets)
          ++ currentNumberOfSurprises;
        
        ResultList.add(total);
      }
      else if(diff == 1 && quotient == 2){
        ResultList.add(total);
      }
      else if(diff == 2 && quotient == 2 && currentNumberOfSurprises < surprisingTriplets){
        ++ currentNumberOfSurprises;
        ResultList.add(total);
      }
    }
    
    
  }
  
}
