package com.example;

import java.io.IOException;
import java.util.List;

public class ProblemB {
    
    enum Result {
	INSUFFICIENT,
	SUFFICIENT,
	SUFFICIENT_WHEN_SURPRISING
    }

    public static void main(String[] a) throws IOException {

	List<String> lines = FileUtil.getLines("/B-large.in");
	
	int cases = Integer.valueOf(lines.get(0));
	
	for(int c=0; c<cases; c++) {
	    String[] tokens = lines.get(c+1).split(" ");
	    
	    int n = Integer.valueOf(tokens[0]); // N = number of Googlers
	    int s = Integer.valueOf(tokens[1]); // S = number of surprising triplets
	    int p = Integer.valueOf(tokens[2]); // P = __at least__ a score of P
	    
	    int sumSufficient = 0;
	    int sumSufficientSurprising = 0;
	    
	    for(int i=0; i<n; i++) {
		int points = Integer.valueOf(tokens[3+i]);
		
		switch(test(points, p)) {
		case SUFFICIENT:
		    sumSufficient++;
		    break;
		    
		case SUFFICIENT_WHEN_SURPRISING:
		    sumSufficientSurprising++;
		    break;
		}
		
//		uSystem.out.println("points "+ points +" ? "+ p +" => "+ result);
	    }
	    
	    System.out.println("Case #"+ (c+1) +": "+ (sumSufficient + Math.min(s, sumSufficientSurprising)));
	    
//	    System.out.println();
//	    System.out.println("N="+ n +", S="+ s +", P="+ p);
//	    System.out.println();
	}
    }

    private static Result test(int n, int p) {
	int fac = n / 3;
	int rem = n % 3;
	
	if(rem == 0) {
	    
//	    int triplet0[] = { fac, fac, fac };
//	    print(n, triplet0);
	    
	    if(fac >= p) {
		return Result.SUFFICIENT;
	    }
	    
	    if(fac > 0 && fac < 10) {
		
		if(fac+1 >= p) {
		    return Result.SUFFICIENT_WHEN_SURPRISING;
		}
		
//		int triplet1[] = { fac+1, fac, fac-1 }; // surprising 
//		print(n, triplet1);
	    }
	    
	    
	} else if(rem == 1) {
	    
//	    int triplet0[] = { fac+1, fac, fac };
//	    print(n, triplet0);
	    
	    if(fac+1 >= p) {
		return Result.SUFFICIENT;
	    }
	    
//	    if(fac > 0 && fac < 10) {
//		int triplet1[] = { fac+1, fac+1, fac-1 };
//		print(n, triplet1);
//	    }
	    
	} else if(rem == 2) {
	    
//	    int triplet0[] = { fac+1, fac+1, fac };
//	    print(n, triplet0);
	    
	    if(fac+1 >= p) {
		return Result.SUFFICIENT;
	    }
	    
	    if(fac < 9) {
//		int triplet1[] = { fac+2, fac, fac }; // surprising
//		print(n, triplet1);

		if(fac+2 >= p) {
		    return Result.SUFFICIENT_WHEN_SURPRISING;
		}
	    }
	    
	} else {
	    throw new RuntimeException("error");
	}
	
	return Result.INSUFFICIENT;
//	System.out.println();
//	System.out.println(n +" => "+ div3 +" ("+ rem +")");
    }
    
//    private static void print(int n, int[] triplet) {
//	System.out.println("n="+ n +" ("+ (n/3) +","+ (n%3) +") => ["+ triplet[0] +","+ triplet[1] +","+ triplet[2] +"]" + (triplet[0]-triplet[2] > 1 ? " *" : ""));
//    }
    
}

/**
 * 
 */
package code.google.codejam;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;

/**
 * @author sunilkumarp
 *
 */
public abstract class Template {
	
	int testcases = 0;
	
	int casePoniter = 0;
	
	PrintWriter writer = null;
	
	BufferedReader reader = null;
	
	String line = null;
	
	int linePointer = -1;
	
	int linePerTestCase = 1;
	
	char lastChar = '!';
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Template template = (Template) Class.forName(args[1]).newInstance(); 
			template.start(args);
		} catch (Exception e) {
			System.out.println(e.getMessage());
			e.printStackTrace(System.out);
		}

	}



	/**
	 * @param args
	 */
	protected void start(String[] args) {
		InputStream io = null;
		OutputStream os = null;
		
		
		
		try {
			
			io = Template.class.getResourceAsStream(args[0]);
			reader = new BufferedReader(new InputStreamReader (io));
			os = new FileOutputStream(new File(args[0].substring(0, args[0].length() -2 )+ "out"));
			writer = new PrintWriter(os);
			testcases = Integer.valueOf(reader.readLine());
			
			solveProblem();
			
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
			e.printStackTrace(System.out);
		} finally {
			try {
				writer.flush();
				writer.close();
			} catch (Exception e) {
				System.out.println(e.getMessage());
				e.printStackTrace(System.out);
			}

			try {
				reader.close();
			} catch (Exception e) {
				System.out.println(e.getMessage());
				e.printStackTrace(System.out);
			}

			try {
				io.close();
			} catch (Exception e) {
				System.out.println(e.getMessage());
				e.printStackTrace(System.out);
			}

			try {
				os.flush();
				os.close();
			} catch (Exception e) {
				System.out.println(e.getMessage());
				e.printStackTrace(System.out);
			}
		}
	}

	public void solveProblem() throws Exception {
		long sTime = System.nanoTime();
		for (;++casePoniter <= testcases;) {
			long sTimeCase = System.nanoTime();
			writeOutput(casePoniter, solveProblemForATestCase());
			System.out.println("Time taken for test case" + "[" + casePoniter + "]:" + (System.nanoTime() - sTimeCase));
		}

		System.out.println("Total time for all test cases:" + (System.nanoTime() - sTime));
	}
	
	protected Object solveProblemForATestCase() throws Exception {
		initializeTestCase();
		printInput();
		return doSolveProblem();
	}

	protected abstract Object doSolveProblem() throws Exception;

	protected abstract void printInput() throws Exception;

	protected abstract void initializeTestCase() throws Exception;

	protected void writeOutput (int caseNo, Object result) {
		String str = "Case #" + caseNo + ": " + result;
		System.out.println("==========" + str + "=============");
		writer.println(str);
	}
	
	public char readChar() throws IOException {
		return lastChar = (char)reader.read();
	}
	
	public char readCharFromLine() throws IOException {
		int length = line.length();
		
		if (linePointer >= length - 1) {
			throw new IllegalStateException("Line has already ended.");
		}
		
		return line.charAt(++linePointer);
	}
	
	public String readLine() throws IOException {
		line = reader.readLine();
		linePointer = -1;
		return line;
	}
	
	public int readNextInteger() {
		int val = 0;
		int length = line.length();
		
		if (linePointer >= length) {
			throw new IllegalStateException("Line has already ended.");
		}
		
		while(++linePointer < length) {
			if (Character.isDigit(lastChar = line.charAt(linePointer))) {
				val = val * 10 + Character.digit(lastChar, 10);
			} else {
				break;
			}
		}
		
		return val;
	}
	
}
