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

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Lance Chen
 */
public class CodeHelper {

    private static String FILE_ROOT = "D:/workspace/googlecodejam/meta";

    public static List<List<String>> loadInputsExcludes(String fileName) {
        List<List<String>> result = new ArrayList<List<String>>();
        List<String> lines = FileUtil.readLines(FILE_ROOT + fileName);
        int index = 0;
        for (String line : lines) {
            if (index == 0) {
                index++;
                continue;
            }
            if (index % 2 == 1) {
                index++;
                continue;
            }
            List<String> dataList = new ArrayList<String>();
            String[] dataArray = line.split("\\s+");
            for (String data : dataArray) {
                if (data.trim().length() > 0) {
                    dataList.add(data);
                }
            }
            result.add(dataList);
            index++;
        }
        return result;
    }

    public static List<List<String>> loadInputs(String fileName) {
        List<List<String>> result = new ArrayList<List<String>>();
        List<String> lines = FileUtil.readLines(FILE_ROOT + fileName);
        for (String line : lines) {
            List<String> dataList = new ArrayList<String>();
            String[] dataArray = line.split("\\s+");
            for (String data : dataArray) {
                if (data.trim().length() > 0) {
                    dataList.add(data);
                }
            }
            result.add(dataList);
        }
        return result;
    }

    public static List<String> loadInputLines(String fileName) {
        return FileUtil.readLines(FILE_ROOT + fileName);
    }

    public static void writeOutputs(String fileName, List<String> lines) {
        FileUtil.writeLines(FILE_ROOT + fileName, lines);
    }
}

package qualificationRound;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Scanner;


public class B {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);

		int ncases = sc.nextInt();

		StringBuilder sb = new StringBuilder();
		for ( int ncase = 1; ncase <= ncases; ncase++ ) {
			int nGooglers = sc.nextInt();
			int nSuprising = sc.nextInt();
			int p = sc.nextInt();
			int surprises = 0;
			int count = 0;
			for (int i = 0; i < nGooglers; i++) {
				int s = sc.nextInt();
				int q = s/3;
				int rm = s%3;
				int pq = p-q;
				
				if ( s < p)
					continue;

				if ( q >= p  ) {
					count++;
				}
				else if ( pq <= 2 ){
					if ( rm == 0 ) {
						if ( pq == 1 && surprises < nSuprising ) {
							count++;
							surprises++;
						}
					}
					else {
						if ( pq == 1 )
							count++;
						else if ( rm == 2 && surprises < nSuprising ) {
							count++;
							surprises++;
						}
					}
				}
			}

			sb.append("Case #"+ ncase +": " + count +  "\n");
		}

		BufferedOutputStream bos = null;
		bos= new BufferedOutputStream(new FileOutputStream(new File("C:\\Users\\Christian\\workspaceCPDI\\CodeJam2012\\src\\qualificationRound\\res.txt")));
		bos.write(sb.toString().getBytes());
		bos.close();
	}
	
}