/*
 * 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
    }

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.HashMap;


public class Dancing {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			// Open the file that is the first
			// command line parameter
			FileInputStream fstream = new FileInputStream(
					"B-large.in");

			// Convert our input stream to aw
			// DataInputStream
			DataInputStream in = new DataInputStream(fstream);

			FileOutputStream out = new FileOutputStream(
					"B-large.out");
			PrintStream p = new PrintStream(out);

			int lineNo = 1;
			// Continue to read lines while
			// there are still some left to read
			while (in.available() != 0) {
				if (lineNo == 1) {
					cases(in.readLine(), in, p);
				}
				lineNo++;
			}

			in.close();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	
	private static void cases(String firstLine, DataInputStream in,
			PrintStream p) throws IOException {
		int casesNo = Integer.parseInt(firstLine);
		for (int i = 0; i < casesNo; i++) {
			// System.out.print("Case #" + (i + 1) + ": ");
			p.print("Case #" + (i + 1) + ": ");
			String line = in.readLine();
			googlers(line, p);
		}

	}

	private static void googlers(String line, PrintStream p) {
		
		String lines[] = line.split(" ");
		int suprises = Integer.parseInt(lines[1]);
		int reqP = Integer.parseInt(lines[2]);
		int result = 0;
		int number=0;
		int quo = 0;
		int rem = 0;
		for(int i = 3;i<lines.length;i++)
		{
			number =Integer.parseInt(lines[i]);
			if(number==0 && reqP==0)
			{
				
				result=result+1;
				continue;
			}
			if(number ==0 )
				continue;
			quo = number/3;
			rem = number%3;
			rem = rem==0? 0 : 1;
			if(quo>=reqP || (rem+quo)>=reqP)
			{
				result=result+1;
				continue;
			}
			else 
			{
				if(suprises>=1)
				{
					number +=2;
					quo = number/3;
					rem = number%3;
					rem = rem==0? 0 : 1;
					if(quo>=reqP || (rem+quo)>=reqP)
					{
						result=result+1;
						suprises=suprises-1;
						continue;
					}
				
				}
					
			}
		}
		p.println(result+"");
	}

}
