package problem1;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;





public class Problem1 {

    public static void main(String[] args) throws FileNotFoundException, IOException{
        try {
             TextIO.readFile("L:\\Coodejam\\Input\\Input.txt");
        }
        catch (IllegalArgumentException e) {
              System.out.println("Can't open file ");
              System.exit(0);
         }
        
        FileOutputStream fout = new FileOutputStream("L:\\Coodejam\\Output\\output.txt");
        PrintStream ps=new PrintStream(fout);
        
        int cases=TextIO.getInt();
        int googlers=0,surprising=0,least=0;
        for(int i=0;i<cases;i++){
            int counter=0;
            googlers=TextIO.getInt();
            surprising=TextIO.getInt();
            least=TextIO.getInt();
            int score[]=new int[googlers];
            for(int j=0;j<googlers;j++){
                score[j]=TextIO.getInt();
                 }
            
            
            
            
            Arrays.sort(score);
            int temp=0;
            int sup[]=new int[surprising];
            
          for(int j=0;j<googlers && surprising>0;j++){
               if(biggestNS(score[j])<least && biggestS(score[j])==least){
                   surprising--;
                   counter++;
                }
               }
           
            for(int j=0;j<googlers;j++){
                if(surprising==0)temp=biggestNS(score[j]);
                    
                else {
                    temp=biggestS(score[j]);
                    surprising--;     
                } 
                   if(temp>=least)counter++;
           
             }
            
             ps.println("Case #"+(i+1)+": "+counter);
        }
    }
    
   static int biggestNS(int x){
       if(x==0)return 0;
       if(x==1)return 1;
       return ((x-1)/3)+1;
   }
   
   static int biggestS(int x){
       if(x==0)return 0;
       if(x==1)return 1;
       return ((x-2)/3)+2;
   }
}

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

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
/**
 *
 * @author Charles
 */
public class DancingWithGooglers
{

    static final String FILE_NAME = "B";

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException
    {
        ArrayList<String> values = readFile(FILE_NAME + ".in");
        int count = 1;

        PrintWriter outFile = new PrintWriter(new File(FILE_NAME + ".out"));
        for (String line : values)
        {
            String output = processAlgorithm(line, count++);
            System.out.println(output);
            outFile.println(output);
        }
        outFile.close();
    }

    /**
     * Reads the CodeJam files and returns the input as a List of String.
     *
     * @param fileName The name of the file to be read
     * @return the list containing the contents of the file.
     */
    public static ArrayList<String> readFile(String fileName)
    {
        ArrayList<String> results = new ArrayList<String>();
        try
        {
            Scanner inFile = new Scanner(new File(fileName));
            int numberOfLines = Integer.parseInt(inFile.nextLine());
            while (inFile.hasNextLine())
            {
                results.add(inFile.nextLine());
            }

            if (numberOfLines != results.size())
            {
                System.err.println("File size does not match...");
                System.exit(0);
            }

        } catch (FileNotFoundException ex)
        {
            System.err.println("File not found...");
            System.exit(0);
        }
        return results;
    }

    private static String processAlgorithm(String line, int caseNumber)
    {
        StringBuilder result = new StringBuilder("Case #" + caseNumber + ": ");

        Scanner scan = new Scanner(line);

        int numberOfDancers = scan.nextInt();
        int numberOfSuprises = scan.nextInt();
        int highestScore = scan.nextInt();

        int usedSuprises = 0;
        int count = 0;

        Dancer current;
        for (int index = 0; index < numberOfDancers; index++)
        {
            current = new Dancer(scan.nextInt());
            if (current.highScoreWithOutSuprise >= highestScore)
            {
                count++;
            }
            else if (current.highScoreWithSuprise >= highestScore
                    && usedSuprises < numberOfSuprises)
            {
                usedSuprises++;
                count++;
            }
        }
        
        result.append(count);
        return result.toString();
    }
}

class Dancer
{

    int highScoreWithSuprise;
    int highScoreWithOutSuprise;

    public Dancer(int score)
    {
        highScoreWithOutSuprise = highScoreWithSuprise = score / 3;
        int mod = score % 3;
        if (score > 0)
        {
            switch (mod)
            {
                case 0:
                    highScoreWithSuprise += 1;
                    break;
                case 1:
                    highScoreWithOutSuprise += 1;
                    highScoreWithSuprise += 1;
                    break;
                case 2:
                    highScoreWithOutSuprise += 1;
                    highScoreWithSuprise += 2;
                    break;
            }
        }
    }
}
