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.util.*;
import java.io.*;
import java.lang.*;

class DancingGooglers { 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int T = Integer.parseInt(sc.nextLine());
    
    for (int i=0; i<T; i++) {
    	String[] dat = sc.nextLine().split(" ");
    	int N = Integer.parseInt(dat[0]); // number of googlers
    	int S = Integer.parseInt(dat[1]); // number of surprising triplets
    	int p = Integer.parseInt(dat[2]); // required at least
    	int count = 0;
    	
    	List<Googler> g = new ArrayList<Googler>();
    	for (int j=0; j<N; j++) {
    		int score = Integer.parseInt(dat[3+j]);
    		
    		// Possible scores
    		int bestNonSurprising = 0;
    		int bestSurprising = 0;
    		for (int a=0; a<=10; a++) {
    			for (int b=0; b<=10; b++) {
    				int c = score - a - b;
    				if (c < 0 || c > 10) continue;
    				if (Math.abs(a-b) > 2 || Math.abs(b-c) > 2 || Math.abs(a-c) > 2) continue;
    				if (Math.abs(a-b) == 2 || Math.abs(b-c) == 2 || Math.abs(a-c) == 2) {
    					// surprising
    					bestSurprising = Math.max(bestSurprising, Math.max(a, Math.max(b, c)));
    				} else {
    					// no
    					bestNonSurprising = Math.max(bestNonSurprising, Math.max(a, Math.max(b, c)));
    				}
    			}
    		}
    		g.add(new Googler(bestNonSurprising, bestSurprising));
    	}
    	
    	Collections.sort(g);
    	//for (int k=0; k<g.size(); k++) System.out.println(g.get(k).bns+" "+g.get(k).bs);
    	boolean[] taken = new boolean[N];
    	for (int k=0; k<g.size(); k++) {
    		if (g.get(k).bns >= p) { taken[k] = true; count++; }
    	}
    	int countsurprise = 0;
    	for (int k=0; k<g.size(); k++) {
    		if (countsurprise == S) break;
    		if (!taken[k]) {
    			if (g.get(k).bs >= p) { taken[k] = true; count++; countsurprise++; }
    		}
    	}
    	System.out.println("Case #" + (i+1) + ": " + count);
    }
  }
}

class Googler implements Comparable<Googler> {
	int bns = 0, bs = 0; // Best Non, Best Surprising
	Googler(int a, int b) { bns = a; bs = b; }
	
	public int compareTo(Googler g) {
		if (this.bs != g.bs) return g.bs - this.bs;		
		return this.bns - g.bns;
	}
}



