/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 3/3/12
 * Time: 11:00 AM
 * To change this template use File | Settings | File Templates.
 */

import SRMLib.MathLibrary;
import SRMLib.TestSRMLib;
import com.sun.org.apache.bcel.internal.generic.F2D;

import java.io.*;
import java.util.*;
import java.util.zip.Inflater;

public class SRM {
    public static void main(String[] args) throws IOException {
        //TestSRMLib.run();
        codeJam1.main();

        return;
    }
}
class codeJam1 {
    public static void main() throws IOException {
        String inputPath = "E:\\input.txt";
        String outputPath = "E:\\output.txt";
        BufferedReader input = new BufferedReader(new FileReader(inputPath));
        BufferedWriter output = new BufferedWriter(new FileWriter(outputPath));

        String line;
        line = input.readLine();
        int T = Integer.parseInt(line);
        for (int i = 1; i <= T; ++i) {
            line = input.readLine();
            String[] words = line.split(" ");
            int N = Integer.parseInt(words[0]);
            int S = Integer.parseInt(words[1]);
            int p = Integer.parseInt(words[2]);
            int n = 0;
            int res = 0;

            for (int j = 3; j < words.length; ++j) {
                if (p == 0) {
                    res++;
                    continue;
                }

                int t = Integer.parseInt(words[j]);
                if (p == 1) {
                    if (t > 0)
                        res++;
                    continue;
                }
                if (t >= 3 * p - 2)
                    res++;
                else if (t >= 3 * p - 4)
                    n++;
            }

            res += Math.min(n, S);
            output.write("Case #" + i + ": " + res);
            output.newLine();
        }

        input.close();
        output.close();
    }
}

package codejam;

/**
 * @author kaaja
 *
 */

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilenameFilter;

public class Codejam {

	private static File[] getInputFiles(String filePath) {
		File dir = new File(filePath);
		// filter .in files
		FilenameFilter onlyInFiles = new FilenameFilter() {
			public boolean accept(File file, String name) {
				return name.endsWith(".in") || file.isFile();
			}
		};
		File[] inputFiles = dir.listFiles(onlyInFiles);
		return inputFiles;
	}

	private static void processFile(File fileName) {
		System.out.println("Processing file " + fileName);
		try {
			// get reader for current file
			BufferedReader br = new BufferedReader(new FileReader(fileName));
			// create writer using current file + .out
			BufferedWriter bw = new BufferedWriter(new FileWriter(
					fileName.getAbsolutePath() + ".out"));
			// get test cases
			int testCases = Integer.parseInt(br.readLine());
			// process all test cases
			for (int currTestCase = 1; currTestCase <= testCases; currTestCase++) {
				String testCaseLine = br.readLine();
				String[] testCaseLineNumbers = testCaseLine.split(" ");
				int N = Integer.parseInt(testCaseLineNumbers[0]);
				int S = Integer.parseInt(testCaseLineNumbers[1]);
				int p = Integer.parseInt(testCaseLineNumbers[2]);
				int minNormalGradesLimit = Math.max(p * 3 - 2, 0);
				int minSurprisingGradesLimit = Math.max(minNormalGradesLimit - 2, 0);
				int normalBestResults = 0;
				int surprisingBestResults = 0;
				for (int i = 0; i < N; i++) {
					int currentGrades = Integer
							.parseInt(testCaseLineNumbers[3 + i]);
					if (currentGrades >= minNormalGradesLimit)
						normalBestResults++;
					else if (currentGrades >= minSurprisingGradesLimit && surprisingBestResults < S && currentGrades > 0)
						surprisingBestResults++;
				}
				String result = Integer.toString(normalBestResults
						+ surprisingBestResults);
				String currTestCaseResult = "Case #" + currTestCase + ": "
						+ result;
				System.out.println(currTestCaseResult);
				bw.write(currTestCaseResult);
				bw.newLine();
			}
			// close the reader and writer
			br.close();
			bw.flush();
			bw.close();
		} catch (Exception e) {// catch exception if any
			System.err.println("Error: " + e.getMessage());
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println("start");
		// get files to process
		File[] inputFiles = getInputFiles("data");
		if (inputFiles != null) {
			for (File inputFile : inputFiles)
				processFile(inputFile);
		}
	}

}
