import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;


public class DancingWithTheGooglers {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader (new FileReader("B-small.in"));
		PrintWriter out = new PrintWriter(new FileWriter("B-small.out"));
		
		int t = Integer.parseInt(f.readLine());
		for (int i = 0; i < t; i++){
			int c = 0;
			StringTokenizer st = new StringTokenizer(f.readLine());
			int n = Integer.parseInt(st.nextToken());
			int[] ti = new int[n];
			int s = Integer.parseInt(st.nextToken());
			int p = Integer.parseInt(st.nextToken());
			for (int j = 0; j < n; j ++){
				ti[j] = Integer.parseInt(st.nextToken());
				if (ti[j] % 3 == 0){
					if (ti[j] / 3 >= p)
						c++;
					else if (ti[j] / 3 == (p-1) && s > 0 && ti[j] >= 2){
						s--;
						c++;
					}
				}
				else if (ti[j] % 3 == 1){
					if ((ti[j] / 3) + 1 >= p)
						c++;					
				}
				else{
					if (ti[j] / 3 >= p-1)
						c++;
					else if (ti[j] / 3 == (p-2) && s > 0){
						s--;
						c++;
					}
				}
					
				
			}
			out.println("Case #" + (i+1) + ": " + c);
			
			
		}
		out.close();
		System.exit(0);
		
		
		
	}
}

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