import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;


public class Dancing {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// read input file
		File file = new File("B-small-attempt4.in");
		//File file = new File("input.txt");
		BufferedReader br = new BufferedReader(new FileReader(file));
		String ln = "";
		int count = Integer.parseInt(br.readLine());

		// write output file
		File out = new File("outB.txt");
		BufferedWriter bw = new BufferedWriter(new FileWriter(out));
		
		int y = 0;
		for (int i=0; i < count; i++){
			ln = br.readLine();
			y = getY(ln);
			bw.write("Case #" + (i+1) + ": " + y);
			bw.newLine();
		}
		bw.close();
	}
	
	private static int getY(String str) {
		String[] data = str.split(" ");
		int n = Integer.parseInt(data[0]);
		int s = Integer.parseInt(data[1]);
		int p = Integer.parseInt(data[2]);
		int[] t = new int[n];
		for (int i=0; i < n; i++){
			t[i] = Integer.parseInt(data[i+3]);
		}
		int y = 0;
		int base = 0;
		for(int j=0; j < t.length; j++){
			base = t[j] / 3;
			if(base >= p) { y++; }
			else if(base == p-1){
				if(t[j] - (base+p) > base-1 && t[j] > 0){
					y++;
				} else if(s>0 && t[j] - (base+p) > base-2 && t[j] > 0){
					s -= 1;
					y++;
				}
			} else if(base == p-2){
				if(s > 0 && t[j] - (base+p) > base-1 && t[j] > 0){
					s -= 1;
					y++;
				}
			}
		}
		
		return y;
	}

}

package compete;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.StringTokenizer;

public class B {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("B-small-attempt1.in"));
		FileWriter fw = new FileWriter("B-small.out");
		int T = new Integer(in.readLine());
		for (int cases = 1; cases <= T; cases++) {
			StringTokenizer st = new StringTokenizer(in.readLine());
			int N = new Integer(st.nextToken());
			int S = new Integer(st.nextToken());
			int p = new Integer(st.nextToken());

			int[] scores = new int[N];
			for (int j = 0; j < scores.length; j++) {
				scores[j] = new Integer(st.nextToken());
			}

			int max = recurse(scores,0,S,p);
			
			fw.write("Case #" + cases + ": " + max + "\n");
		}
		fw.flush();
		fw.close();
	}

	private static int recurse(int[] sc, int pos, int nbS, int p) {
		if (pos==sc.length) {
			if (nbS==0) return 0;
			else return Integer.MIN_VALUE;
		}
		int somme = sc[pos];
		int a0=0, a1=0, a2=0, a2s=0, a3s=0, a4s=0;
		// a, a-2, a-2 surprising
		if (( (somme>=2) && ((somme+4)<=30) && ((somme+4)%3)==0) && (nbS>0)) {
			int reste = recurse(sc,pos+1,nbS-1,p);
			int a = (somme+4)/3;
			if (a>=p) {
				a4s=reste+1;
			} else {
				a4s = reste;
			}
		}
		// a, a-1, a-2 surprising
		if ((( (somme>=2) && ((somme+3)<=30) && ((somme+3)%3)==0) && (nbS>0))) {
			int reste = recurse(sc,pos+1,nbS-1,p);
			int a = (somme+3)/3;
			if (a>=p) {
				a3s=reste+1;
			} else {
				a3s = reste;
			}
		}
		// a, a, a-2 surprising
		if (( (somme>=2) && ((somme+2)<=30) && ((somme+2)%3)==0)&&(nbS>0)) {
			int reste = recurse(sc,pos+1,nbS-1,p);
			int a = (somme+2)/3;
			if (a>=p) {
				a2s=reste+1;
			} else {
				a2s = reste;
			}
		}
		// a, a-1, a-1 
		if (( (somme>=1) && ((somme+2)<=30) && ((somme+2)%3)==0)) {
			int reste = recurse(sc,pos+1,nbS,p);
			int a = (somme+2)/3;
			if (a>=p) {
				a2=reste+1;
			} else {
				a2 = reste;
			}
		}
		// a, a, a-1 
		if (( (somme>=1) && ((somme+1)<=30) && ((somme+1)%3)==0)) {
			int reste = recurse(sc,pos+1,nbS,p);
			int a = (somme+1)/3;
			if (a>=p) {
				a1=reste+1;
			} else {
				a1 = reste;
			}
		}
		// a, a, a 
		if ((somme%3)==0) {
			int reste = recurse(sc,pos+1,nbS,p);
			int a = somme/3;
			if (a>=p) {
				a0=reste+1;
			} else {
				a0 = reste;
			}
		}
		int max = Math.max(Math.max(a4s,a3s), Math.max(Math.max(a0,a1), Math.max(a2, a2s)));
		return max;
	}

}
