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 com.google.codejam2011.dancing;

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;
import java.util.ArrayList;

public class Runner {

	public ArrayList<String> output = new ArrayList<String>();
	
	public class DancingEvent {
		private ArrayList<Score> scoreList;
		private int surprisingCount;
		private int maxValue;

		public ArrayList<Score> getScoreList() {
			return scoreList;
		}

		public void setScoreList(ArrayList<Score> scoreList) {
			this.scoreList = scoreList;
		}

		public int getSurprisingCount() {
			return surprisingCount;
		}

		public void setSurprisingCount(int surprisingCount) {
			this.surprisingCount = surprisingCount;
		}

		public int getMaxValue() {
			return maxValue;
		}

		public void setMaxValue(int maxValue) {
			this.maxValue = maxValue;
		}
	}

	private class Score {
		private final static int JURY_COUNT = 3;
		private int values[] = new int[JURY_COUNT];
		private int sum;
		private int max;
		private int maxSurprise;

		public Score(int pSum) {
			this.sum = pSum;
		}

		public void calcValues() {
			if (this.sum == 0) {
				max = 0;
				maxSurprise = 0;
			} else {
				int base = this.sum / JURY_COUNT;
				int rest = this.sum % JURY_COUNT;

				for (int i = 0; i < values.length; i++) {
					values[i] = base;
					if (rest != 0) {
						values[i]++;
						rest--;
					}
				}

				rest = this.sum % JURY_COUNT;

				if (rest == 0) {
					max = base;
					maxSurprise = base + 1;
				} else {
					max = base + 1;
					if (rest == 1)
						maxSurprise = base + 1;
					else
						maxSurprise = base + 2;
				}
			}
		}

		public boolean isBigger(int p) {
			if (this.max >= p)
				return true;
			else
				return false;
		}

		public boolean isSurpriseBigger(int p) {
			if (this.maxSurprise >= p)
				return true;
			else
				return false;
		}
	}

	public class InputParser {
		private BufferedReader br;

		public InputParser(String path, ArrayList<DancingEvent> dances) {
			try {
				br = new BufferedReader(new FileReader(new File(path)));

				String inputLine;
				int T = 0, N, S, P, counter = 0;
				int countBase = 0, counterSurprise = 0;
				try {
					while ((inputLine = br.readLine()) != null) {
						if (T == 0) {
							T = new Integer(inputLine);
						} else {
							String input[] = inputLine.split(" ");
							N = new Integer(input[0]);
							S = new Integer(input[1]);
							P = new Integer(input[2]);
							countBase = 0;
							counterSurprise = 0;
							ArrayList<Score> scores = new ArrayList<Runner.Score>();

							for (int i = 3; i < input.length; i++) {
								Score tmpScore = new Score(
										new Integer(input[i]));
								tmpScore.calcValues();
								scores.add(tmpScore);

								if (tmpScore.isBigger(P))
									countBase++;
								else if (tmpScore.isSurpriseBigger(P))
									counterSurprise++;
							}

							DancingEvent dance = new DancingEvent();
							dance.setMaxValue(P);
							dance.setScoreList(scores);
							dance.setSurprisingCount(S);
							dances.add(dance);
							output.add("Case #"+ counter + ": "
											+ ((Integer) Math.min(
													counterSurprise, S) + (Integer) countBase));
						}
						counter++;
					}
				} catch (NumberFormatException e) {
					e.printStackTrace();
					System.out.println("Could not parse Numbers");
				} catch (IOException e) {
					e.printStackTrace();
					System.out.println("Could not Read Lines");
				}
			} catch (FileNotFoundException e) {
				e.printStackTrace();
				System.out.println("Could not open file");
			}

		}
	}
	
	public void writeOutput(String path){
		BufferedWriter bw;
		try {
			bw = new BufferedWriter(	new FileWriter(new File(path)));
			for(String s : output)
				try {
					bw.write(s + "\r\n");
				} catch (IOException e) {
					e.printStackTrace();
					System.out.println("Could not write in file");
				}
			bw.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("Could not open file");
		}

	}

	public static void main(String args[]) {
		Runner r = new Runner();
		ArrayList<DancingEvent> dances = new ArrayList<Runner.DancingEvent>();
		r.new InputParser("src/com/google/codejam2011/dancing/input.txt",
				dances);
		r.writeOutput("src/com/google/codejam2011/dancing/output.txt");
	}
}
