package dancinggooglers;

import java.io.File;
import java.util.Scanner;

public class DanceScoreCalculator {


    public static void main(String[] args) {
        if(args.length <= 0 || args[0] == null) {
            System.out.println("You must enter a file to read");
            System.out.println("Usage: blah <filename>");
            System.exit(0);
        }

        File argFile = new File(args[0]);
        try {
            Scanner googleSpeakScanner = new Scanner(argFile);
            String firstLine = googleSpeakScanner.nextLine();
            Integer linesToScan = new Integer(firstLine);
            for(int i = 1; i <= linesToScan; i++) {
                String googleDancerLine = googleSpeakScanner.nextLine();
                DanceScoreCase danceCase = new DanceScoreCase(googleDancerLine);
                System.out.println(String.format("Case #%d: %d", i, danceCase.maxDancersThatCouldPass()));
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}

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

public class B {

	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new FileReader(args[0]));
		in.readLine();
		
		String[] segments;
		int[] scores;
		int numCase = 0;
		while (in.ready()) {
			segments = in.readLine().split(" ");
			scores = new int[segments.length - 3];
			for (int i = 0; i < scores.length; ++i) {
				scores[i] = Integer.parseInt(segments[i + 3]);
			}
			solve(++numCase, Integer.parseInt(segments[1]), Integer.parseInt(segments[2]), scores);
		}
	}
	
	private static void solve(int caseNum, int s, int p, int[] scores) {
		int max = 0;
		
		if (p == 0) {
			max = scores.length;
		} else if (p == 1) {
			for (int i = 0; i < scores.length; ++i) {
				if (scores[i] >= 1) {
					++max;
				}
			}
		} else {
			int limit1 = (p - 2) * 3 + 2;
			int limit2 = limit1 + 1;
			
			int needS = 0;
			
			int score;
			for (int i = 0; i < scores.length; ++i) {
				score = scores[i];
				if (score < limit1) {
					continue;
				}
				
				if (score <= limit2) {
					++ needS;
					continue;
				}
				
				++max;
			}
			
			max += Math.min(needS, s);
		}
		
		System.out.printf("Case #%d: %d\n", caseNum, max);
	}
}