import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


public class Dancing_improved {
	
	static int f_Superan_limites(String params){
		  int superan_limite=0;
		  String[] parametros=params.split(" ");
		  
		  int n_participantes= Integer.parseInt(parametros[0]);
		  int n_sorprendidos= Integer.parseInt(parametros[1]);
		  int nota_limite= Integer.parseInt(parametros[2]);
		  
		  int suma_notas, resto, nota_juego;
		  for(int i=3;i<parametros.length;i++){ // Recorro las sumas de los participantes
			  
			  suma_notas=Integer.parseInt(parametros[i]);
			  resto=suma_notas%3;
			  
			  if(resto==0){ // el resto es el número triplicado!
				  nota_juego=suma_notas/3;
				  if(nota_juego>=nota_limite){
					  superan_limite++;
				  }else if(nota_juego-1>=0 && n_sorprendidos>0 && ((nota_juego+1)>=nota_limite || (nota_juego+2)>=nota_limite)){ // no supera el límite pero podría hacerlo si quedan sorprendidos
					  n_sorprendidos--;
					  superan_limite++;
				  }
			  }else if((suma_notas+1)%3==0){ // Tendré que jugar con el valor en +-1
				  nota_juego=(suma_notas+1)/3;
				  if(nota_juego-1>=0 && nota_juego>=nota_limite){
					  superan_limite++;
				  }else if(nota_juego-1>=0 && n_sorprendidos>0 && (nota_juego+1)>=nota_limite){
					  n_sorprendidos--;
					  superan_limite++;
				  }
			  }else if((suma_notas+2)%3==0){ // Tendré que jugar con el valor en +-2
				  nota_juego=(suma_notas+2)/3;
				  if(nota_juego-1>=0 && nota_juego>=nota_limite){
					  superan_limite++;
				  }		  
			  }			  
		  }
		  return superan_limite;
	}
	
	public static void main(String[] args) throws IOException {
		FileReader fr = new FileReader(args[0]);
		BufferedReader bf = new BufferedReader(fr);
		int ntest=0;
		
		FileWriter fstream = new FileWriter("out.txt");
		BufferedWriter out = new BufferedWriter(fstream);
		
		String lines = bf.readLine();
		String liner, linew;
		int lines_r=0;
		String[] numbers;
		int total;
		
		while((liner = bf.readLine())!=null && lines_r<=Integer.parseInt(lines)) {
			ntest++;
			numbers=liner.split(" ");
			total=f_Superan_limites(liner);
			linew="Case #"+ntest+": "+total+"\n";
			out.write(linew);
			lines_r++;
		}
		out.close();
		fr.close();
	}
}

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

public class Main {
	
	Scanner in;
	PrintWriter out;
	
	static final String problemName = "B";
	
	static void asserT(boolean e) {
		if (!e) {
			throw new Error();
		}
	}
	
	
	static class Triple {
		int a;
		int b;
		int c;
		
		int max;
		int min;
		
		Triple(int a, int b, int c) {
			this.a = a;
			this.b = b;
			this.c = c;
			
			max = Math.max(a, Math.max(b, c));
			min = Math.min(a, Math.min(b, c));
			asserT(max - min <= 2);
		}
		
		boolean isSurprising() {
			return max - min == 2;
		}
	}
	
	static class Point {
		ArrayList <Triple> list = new ArrayList<Triple>();
		int sMax = -1;
		int uMax = -1;
						
		void add(int a, int b, int c) {
			list.add(new Triple(a, b, c));
		}
		
		int getSurpriseMaximum() {
			if (sMax == -1) {
				sMax = 0;
				for (Triple curr : list) {
					if (curr.isSurprising()) {
						sMax = Math.max(curr.max, sMax);
					}
				}
			}
			return sMax;
		}
		
		int getUsualMaximum() {
			if (uMax == -1) {
				uMax = 0;
				for (Triple curr : list) {
					if (!curr.isSurprising()) {
						uMax = Math.max(curr.max, uMax);
					}
				}
			}
			return uMax;
		}
	}
	
	static final int MAX_COUNT = 100;
	static final int MAX_POINTS = 10;
	
	Point p[] = new Point[31];
	
	int res[][];
	int scores[];
	
	int gen(int idx, int remainSurp, int least) {
		if (idx == -1) {
			if (remainSurp == 0) {
				return 0;
			} else {
				return Integer.MIN_VALUE / 10;
			}
		}
		if (res[idx][remainSurp] != -1) {
			return res[idx][remainSurp];
		}
		int ans = 0;
		int score = scores[idx];
		int maxSurp = p[score].getSurpriseMaximum();
		int maxUsual = p[score].getUsualMaximum();
		
		if (remainSurp != 0) {
			if (maxUsual >= least || maxSurp >= least) {
				ans++;
			}
			ans += gen(idx - 1, remainSurp - 1, least);
		} 
		int ans2 = 0;
		if (maxUsual >= least) {
			ans2++;
		}
		ans2 += gen(idx - 1, remainSurp, least);
		
		res[idx][remainSurp] = Math.max(ans, ans2);
		return res[idx][remainSurp];
	}
	
	
	int solveOne() {
		scores = new int[in.nextInt()];
		int nSurprising = in.nextInt();
		int least = in.nextInt();
		for (int i = 0; i < scores.length; i++) {
			scores[i] = in.nextInt();
		}
		
		res = new int[scores.length][nSurprising + 1];
		for (int []ar : res) {
			Arrays.fill(ar, -1);
		}
		
		return gen(scores.length - 1, nSurprising, least);
	}
	
	void solve() {
		for (int i = 0; i < p.length; i++) {
			p [i] = new Point();
		}
		for (int i = 0; i <= 10; i++) {
			for (int j = i; j <= 10; j++) {
				for (int k = j; k <= 10; k++) {
					if (k - i <= 2) {
						int sum = i + j + k;
						p[sum].add(i, j, k);
					}
				}
			}
		}
		
		int nTests = in.nextInt();
		in.nextLine();
		for (int i = 0; i < nTests; i++) {
			out.println("Case #" + (i+1) + ": " + solveOne());
		}
	}
	
	void run() {
		try {
			in = new Scanner(new FileReader("C:/GCJ/" + problemName + ".in"));
			out = new PrintWriter(new FileWriter("C:/GCJ/" + problemName + ".out"));
		} catch (IOException e) {
			in = new Scanner(System.in);
			out = new PrintWriter(System.out);
		//	throw new Error();
		}
		
		try {
			solve();
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}