/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package IO;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
    
/**
 * 
 * @author dannocz
 */
public class InputReader {
    
    public static Input readFile(String filename){
        try {
              
              /*  Sets up a file reader to read the file passed on the command
          77        line one character at a time */
              FileReader input = new FileReader(filename);
              
              /* Filter FileReader through a Buffered read to read a line at a
                 time */
              BufferedReader bufRead = new BufferedReader(input);
              
              String line;    // String that holds current file line
              int count = 0;  // Line number of count 
              ArrayList<String> cases= new ArrayList<String>();
              
              // Read first line
              line = bufRead.readLine();
              int noTestCases=Integer.parseInt(line);
              count++;
              
              // Read through file one line at time. Print line # and line
              while (count<=noTestCases){
                  //System.out.println("Reading. "+count+": "+line);
                  line = bufRead.readLine();
                  cases.add(line);
                  count++;
              }
              
              bufRead.close();
              
              return new Input(noTestCases,cases);
              
          }catch (ArrayIndexOutOfBoundsException e){
              /* If no file was passed on the command line, this expception is
              generated. A message indicating how to the class should be
              called is displayed */
              e.printStackTrace();        
  
          }catch (IOException e){
              // If another exception is generated, print a stack trace
              e.printStackTrace();
          }
        
        return null;
          
      }// end main
    }

package codejam;
import java.util.ArrayList;
import java.util.Collections;
public class DWG {
	int findCount(int N,int S,int p,ArrayList<Integer>arr){
		int count = 0;
		Collections.sort(arr);
		int i = 0;
		while( S != 0 && i<arr.size()){
			int val = 0;
			
			val = arr.get(i);			
			if( (val -3)%3 == 0 && (val-3)>=0){
				int q = (val -3 ) / 3;
				if( (q+2) >=p){
					count++;
					arr.set(i, -1);
					S--;
				}
			}
			else if( (val -2)%3 == 0 &&(val-2)>=0){
				int q = (val -2 ) / 3;
				if( (q+2) >=p){
					count++;
					arr.set(i, -1);
					S--;
				}
			}
			else if( (val -4)%3 == 0 && (val -4)>=0){
				int q = (val -4 ) / 3;
				if( (q+2) >=p){
					count++;
					arr.set(i, -1);
					S--;
				}
			}
			i++;
		}
		for(i = 0; i<N;i++){
			int val = arr.get(i);
			if( val >=0){
				if( (val)%3 == 0){
					int q = (val ) / 3;
					if( (q) >=p){
						count++;
						arr.set(i, -1);						
					}
				}
				else if( (val - 2)%3 == 0 && (val - 2)>=0){
					int q = (val -2 ) / 3;
					if( (q+1) >=p){
						count++;
						arr.set(i, -1);
						
					}
				}
				else if( (val-1)%3 == 0 && (val - 1)>=0){
					int q = (val -1 ) / 3;
					if( (q+1) >=p){
						count++;
						arr.set(i, -1);
						
					}
				}
				
			}
		}	
		
		return count;
	}
	public static void main(String []args){
		DWG d = new DWG();
		
		FileRead fr = new FileRead("B-small-attempt1.in");
		FileWrite fw = new FileWrite("B-small-ouput1.txt");
		
		int num = 0;
		
		int t = fr.readNextInt();
		for(int i = 0; i< t ; i++){
			int arr[] = fr.readNextIntArray();
			
			ArrayList<Integer> a = new ArrayList<Integer>();
			int j = 0;
			for(;j<arr[0];j++){
				a.add(arr[j+3]);
			}
			
			num = d.findCount(arr[0], arr[1], arr[2], a);
			fw.writeLine("Case #"+(i+1)+": "+num);
			
		}
		fw.close();
		fr.close();

	}
}
