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

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

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author mohamedmohideenebrahim
 */
public class Codejam {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        try {
            Scanner scanner = new Scanner(new File(args[0]));
            int testCaseNum = scanner.nextInt();
            scanner.nextLine();
            for (int i = 0; i < testCaseNum; i++) {
                System.out.println("Case #" + (i + 1) + ": " + getString(scanner.nextLine()));
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Codejam.class.getName()).log(Level.SEVERE, null, ex);
        }



    }

    public static int getString(String input) {
        String[] inputArray = input.split(" ");
        //System.out.println(input);
        int noOfSurprise = Integer.parseInt(inputArray[1]);
        int minMark = Integer.parseInt(inputArray[2]);

        int countedSurprise = 0;
        int countedMinMark = 0;

        for (int i = 3; i < inputArray.length; i++) {
            int mark = Integer.parseInt(inputArray[i]);
            int remainder = mark % 3;
            int quotient = mark / 3;
            
            if(remainder == 0)
            {
                //System.out.println(quotient+","+quotient+","+quotient);
                //System.out.println((quotient-1)+","+quotient+","+(quotient+1));
                if(quotient >= minMark)
                {
                    countedMinMark++;
                    //System.out.println("Matched "+quotient+","+quotient+","+quotient);
                }
                else if(mark > 2 && countedSurprise != noOfSurprise && (quotient+1) >= minMark)
                {
                    //System.out.println("Matched "+(quotient-1)+","+quotient+","+(quotient+1));
                    countedMinMark++;
                    countedSurprise++;
                }
                //System.out.println();
            }
            else if(remainder == 1)
            {
                //System.out.println(quotient+","+quotient+","+(quotient+1));
                if(quotient+1 >= minMark)
                {
                    //System.out.println("Matched "+quotient+","+quotient+","+(quotient+1));
                    countedMinMark++;
                }
                //System.out.println();
            }
            else if(remainder == 2)
            {
                //System.out.println((quotient+1)+","+quotient+","+(quotient+1));
                //System.out.println(quotient+","+quotient+","+(quotient+2));
                if(quotient+1 >= minMark)
                {
                    //System.out.println("Matched "+(quotient+1)+","+quotient+","+(quotient+1));
                    countedMinMark++;
                }
                else if(mark > 2 && countedSurprise != noOfSurprise && (quotient+2) >= minMark)
                {
                    countedMinMark++;
                    countedSurprise++;
                    //System.out.println("Matched "+quotient+","+quotient+","+(quotient+2));
                }
                //System.out.println();
                
            }
            //System.out.println("Mark " + mark + " Quotient " + quotient
             //       + " Counted MinMark " + countedMinMark + " counted surprise " + countedSurprise);
            //System.out.println();
        }
        return countedMinMark;

    }
}
