package code12.qualification;

import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;

public class B {
	public static String solve(int N, int S, int p, int[] t) {
		
		// 3a 		-> (a, a, a), *(a - 1, a, a + 1)
		// 3a + 1	-> (a, a, a + 1), *(a - 1, a + 1, a + 1)
		// 3a + 2	-> (a, a + 1, a + 1), *(a, a, a + 2)
		
		int numPNoS = 0;
		int numPWithS = 0;
		
		for (int i = 0; i < N; i++) {
			int a = (int)Math.floor(t[i] / 3);
			int r = t[i] % 3;
			
			switch (r) {
			case 0:
				if (a >= p) {
					numPNoS++;
				} else if (a + 1 >= p && a - 1 >= 0) {
					numPWithS++;
				}
				break;
			case 1:
				if (a >= p || a + 1 >= p) {
					numPNoS++;
				}
				break;
			case 2:
				if (a >= p || a + 1 >= p) {
					numPNoS++;
				} else if (a + 2 >= p) {
					numPWithS++;
				}
				break;
			}
		}
		
		return "" + (numPNoS + Math.min(S, numPWithS));
	}

	public static void main(String[] args) throws Exception {
		// file name
		//String fileName = "Sample";
		//String fileName = "B-small";
		String fileName = "B-large";
		
		// file variable
		File inputFile = new File(fileName + ".in");
		File outputFile = new File(fileName + ".out");
		Scanner scanner = new Scanner(inputFile);
		FileWriter writer = new FileWriter(outputFile);

		// problem variable
		int totalCase;
		int N, S, p;
		int[] t;

		// get total case
		totalCase = scanner.nextInt();

		for (int caseIndex = 1; caseIndex <= totalCase; caseIndex++) {
			// get input
			N = scanner.nextInt();
			S = scanner.nextInt();
			p = scanner.nextInt();
			t = new int[N];
			
			for (int i = 0; i < N; i++) {
				t[i] = scanner.nextInt();
			}
			
			String output = "Case #" + caseIndex + ": " + solve(N, S, p, t);
			System.out.println(output);
			writer.write(output + "\n");
		}
		scanner.close();
		writer.close();
	}
}

import java.io.*;
import java.util.StringTokenizer;

/**
 * User: Grant
 * Date: 14/04/12
 * Time: 22:51
 */
public class ProblemB {
    public static void main(String[] args) throws IOException {

        // Prepare output file
        File outputFile = new File("E:\\Programming\\Java\\CodeJam\\resources\\problemBOutput.txt");
        if(outputFile.exists()) {
            outputFile.delete();
        }

        FileWriter fileWriter = new FileWriter(outputFile);
        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

        // Read input file
        File inputFile = new File("E:\\Programming\\Java\\CodeJam\\resources\\TestInput.txt");
        FileReader fileReader = new FileReader(inputFile);
        BufferedReader bufferedReader = new BufferedReader(fileReader);

        Integer testCases = Integer.parseInt(bufferedReader.readLine().trim());
        for(int i = 0; i < testCases; i++) {
            StringTokenizer st = new StringTokenizer(bufferedReader.readLine().trim(), " ");
            int googlerCount = Integer.parseInt(st.nextToken().trim());
            int totalSurpriseCount = Integer.parseInt(st.nextToken().trim());
            int bestResult = Integer.parseInt(st.nextToken().trim());

            int outputNum = 0;

            int surprisesUsed = 0;
            start: for(int j = 0; j < googlerCount; j++) {
                int total = Integer.parseInt(st.nextToken().trim());
                boolean surpriseAvailable = false;
                for(int x = 0; x <= 10; x++) {
                    for(int y = 0; y <= 10; y++) {
                        for(int z = 0; z <= 10; z++) {
                            if(x + y + z == total
                                    && (x >= bestResult
                                        || y >= bestResult
                                        || z >= bestResult)) {
                                if(Math.abs(x-y) <= 1 && Math.abs(y-z) <= 1 && Math.abs(x-z) <= 1) {
                                    outputNum++;
                                    continue start;
                                }
                                if(!surpriseAvailable
                                    && surprisesUsed < totalSurpriseCount
                                    && Math.abs(x-y) <= 2 && Math.abs(y-z) <= 2 && Math.abs(x-z) <= 2) {
                                    surpriseAvailable = true;
                                }
                            }
                        }
                    }
                }
                if(surpriseAvailable) {
                    surprisesUsed++;
                    outputNum++;
                }
            }

            bufferedWriter.write("Case #" + (i+1) + ": " + outputNum + "\n");
        }

        bufferedReader.close();
        fileReader.close();

        // Write output file
        bufferedWriter.flush();
        fileWriter.flush();
        bufferedWriter.close();
        fileWriter.close();
    }
}


















