package com.gcj.parser;

public class MaxPoints {

	public static int normal(int value){
		int toReturn = 0;
		switch (value) {
		case 0 : toReturn = 0 ; break;
		case 1 : toReturn = 1 ; break;
		case 2 : toReturn = 1 ; break;
		case 3 : toReturn = 1 ; break;
		case 4 : toReturn = 2 ; break;
		case 5 : toReturn = 2 ; break;
		case 6 : toReturn = 2 ; break;
		case 7 : toReturn = 3 ; break;
		case 8 : toReturn = 3 ; break;
		case 9 : toReturn = 3 ; break;
		case 10 : toReturn = 4 ; break;
		case 11 : toReturn = 4 ; break;
		case 12 : toReturn = 4 ; break;
		case 13 : toReturn = 5 ; break;
		case 14 : toReturn = 5 ; break;
		case 15 : toReturn = 5 ; break;
		case 16 : toReturn = 6 ; break;
		case 17 : toReturn = 6 ; break;
		case 18 : toReturn = 6 ; break;
		case 19 : toReturn = 7 ; break;
		case 20 : toReturn = 7 ; break;
		case 21 : toReturn = 7 ; break;
		case 22 : toReturn = 8 ; break;
		case 23 : toReturn = 8 ; break;
		case 24 : toReturn = 8 ; break;
		case 25 : toReturn = 9 ; break;
		case 26 : toReturn = 9 ; break;
		case 27 : toReturn = 9 ; break;
		case 28 : toReturn = 10 ; break;
		case 29 : toReturn = 10 ; break;
		case 30 : toReturn = 10 ; break;

		}

		return toReturn;
	}

	public static int surprising(int value){
		int toReturn = 0;
		switch (value) {
		case 0 : toReturn = 0 ; break;
		case 1 : toReturn = 1 ; break;
		case 2 : toReturn = 2 ; break;
		case 3 : toReturn = 2 ; break;
		case 4 : toReturn = 2 ; break;
		case 5 : toReturn = 3 ; break;
		case 6 : toReturn = 3 ; break;
		case 7 : toReturn = 3 ; break;
		case 8 : toReturn = 4 ; break;
		case 9 : toReturn = 4 ; break;
		case 10 : toReturn = 4 ; break;
		case 11 : toReturn = 5 ; break;
		case 12 : toReturn = 5 ; break;
		case 13 : toReturn = 5 ; break;
		case 14 : toReturn = 6 ; break;
		case 15 : toReturn = 6 ; break;
		case 16 : toReturn = 6 ; break;
		case 17 : toReturn = 7 ; break;
		case 18 : toReturn = 7 ; break;
		case 19 : toReturn = 7 ; break;
		case 20 : toReturn = 8 ; break;
		case 21 : toReturn = 8 ; break;
		case 22 : toReturn = 8 ; break;
		case 23 : toReturn = 9 ; break;
		case 24 : toReturn = 9 ; break;
		case 25 : toReturn = 9 ; break;
		case 26 : toReturn = 10 ; break;
		case 27 : toReturn = 10 ; break;
		case 28 : toReturn = 10 ; break;
		case 29 : toReturn = 10 ; break;
		case 30 : toReturn = 10 ; break;

		}
		return toReturn;
	}

}

package year2012.DancingWiththeGooglers;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

final class DancingWiththeGooglers {

	/**
	 * @param args
	 * @throws IOException
	 */
	static class Triplet {
		public boolean ableMax = false;
		public boolean ableSurprising = true;
		public boolean beMaxMustSurprise = false;

		Triplet(int totalScore, int maxScore) {
			int mean = totalScore / 3;
			int remainder = totalScore % 3;
			if (totalScore == 29 || totalScore == 30) {
				ableMax = true;
			} 
			else if (totalScore == 0 || totalScore == 1)
			{
				ableSurprising = false;
				if (maxScore <= totalScore)
				{
					ableMax = true;
				}
				else ableMax = false;
			}
			else if (mean >= maxScore) {
				ableMax = true;
			} else if (mean == (maxScore - 1)) {
				if (remainder == 2 || remainder == 1)
					ableMax = true;
				if (remainder == 0)
					beMaxMustSurprise = true;
			} else if (mean == (maxScore - 2)) {
				if (remainder == 2)
					beMaxMustSurprise = true;
			}
		}
	}

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

		String file = "B-large";
		Scanner sc = new Scanner(new FileReader(file + ".in"));
		PrintWriter pw = new PrintWriter(new FileWriter(file + ".out"));

		int T = sc.nextInt();
		for (int i = 0; i < T; i++) {

			int N = sc.nextInt();
			int S = sc.nextInt(); // surprising
			int p = sc.nextInt();

			int totalBeAlwaysMax = 0;
			int totalBeMaxMustSurprising = 0;
			int totalNotSurpriseAbleMax = 0;

			int result = 0;

			for (int i1 = 0; i1 < N; i1++) {
				Triplet temp = new Triplet(sc.nextInt(), p);
				if (temp.ableMax  && temp.ableSurprising)
					totalBeAlwaysMax++;
				if (temp.beMaxMustSurprise == true)
					totalBeMaxMustSurprising++;
				if (!temp.ableSurprising && temp.ableMax)
				{
					totalNotSurpriseAbleMax++;
				}
				
			}

			if (S <= totalBeMaxMustSurprising) {
				result = totalBeAlwaysMax + S + totalNotSurpriseAbleMax ;
			} else {
				result = totalBeAlwaysMax + totalBeMaxMustSurprising + totalNotSurpriseAbleMax;
			}

			pw.println("Case #" + (i + 1) + ": " + result);
			// pw.println();

		}
		pw.flush();
		pw.close();
		sc.close();
	}
}
