package com.menzus.gcj._2012.qualification.b;

import com.menzus.gcj.common.InputBlockParser;
import com.menzus.gcj.common.OutputProducer;
import com.menzus.gcj.common.impl.AbstractProcessorFactory;

public class BProcessorFactory extends AbstractProcessorFactory<BInput, BOutputEntry> {
    public BProcessorFactory(String inputFileName) {
	super(inputFileName);
    }

    @Override
    protected InputBlockParser<BInput> createInputBlockParser() {
	return new BInputBlockParser();
    }

    @Override
    protected OutputProducer<BInput, BOutputEntry> createOutputProducer() {
	return new BOutputProducer();
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

public class Puzzle2 {

    
    public static int countGooglersByTarget(int target, int numberOfSurprising, List<Integer> googlerScores) {
        int count = 0;
        
        int totalTarget = 3*target;

        for (int i = 0; i < googlerScores.size(); i++) {
            int totalGooglerSum = googlerScores.get(i);
            if(totalGooglerSum >= totalTarget -2) {
                count ++;    
            } else if(totalGooglerSum >0 && totalGooglerSum +2 >= totalTarget -2 && numberOfSurprising >0) {
                count ++; 
                numberOfSurprising--;   
            }
        }
        
        return count;
    }

    public static void main(String[] args) {
    
        String input = "100\n" +
                "6 2 8 29 20 8 18 18 21\n" +
                "57 12 6 14 14 26 14 20 14 15 15 14 20 20 17 18 13 8 3 11 24 29 15 14 10 15 27 25 30 15 14 25 14 0 3 29 24 14 15 23 17 14 10 14 27 2 14 14 14 15 14 15 14 18 0 16 15 29 14 7\n" +
                "40 0 0 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30\n" +
                "50 1 7 17 18 17 17 17 18 17 17 18 17 18 18 20 18 18 20 17 18 17 17 2 17 18 28 17 18 17 18 17 18 17 19 18 3 17 17 14 18 17 17 28 24 20 7 18 22 16 17 18 14\n" +
                "40 31 6 2 23 26 1 13 2 27 10 2 11 10 10 24 10 1 30 14 5 29 22 8 3 12 21 2 12 28 3 13 23 10 24 13 20 1 7 6 2 16 26\n" +
                "79 8 6 5 17 15 30 22 14 0 20 28 18 14 14 30 18 6 14 14 15 14 14 29 15 20 22 6 11 14 15 15 14 15 14 19 14 14 15 15 14 14 24 30 11 20 28 14 14 15 26 14 14 14 25 9 14 14 3 8 15 15 14 15 21 6 14 15 2 7 9 13 30 7 15 4 27 15 8 17 6 11\n" +
                "17 3 1 23 15 14 3 26 4 18 16 29 6 16 9 27 17 27 6 30\n" +
                "55 55 1 16 20 21 17 17 6 12 12 26 24 24 16 24 12 5 28 21 27 24 14 8 12 24 7 6 19 17 18 14 24 22 21 10 3 19 8 14 14 14 5 18 6 10 17 2 7 2 2 17 2 28 12 26 6 23\n" +
                "99 21 10 9 2 11 27 7 14 11 2 0 21 14 13 17 9 16 11 10 6 19 14 13 3 14 20 28 19 2 21 22 15 2 5 25 21 25 29 21 28 4 25 19 24 6 10 1 17 20 3 9 4 27 1 20 29 26 21 17 14 30 29 6 10 9 28 10 28 12 13 0 17 21 17 29 21 17 26 10 27 13 8 7 4 12 15 22 19 18 18 4 18 12 3 12 17 7 4 16 15 3\n" +
                "34 0 8 5 18 1 5 14 6 18 27 13 21 10 26 9 28 4 23 17 26 30 0 18 14 1 12 16 26 18 8 1 5 12 4 16 11\n" +
                "49 13 4 9 8 8 8 9 8 10 9 12 10 4 0 9 16 0 9 9 2 12 2 30 9 9 8 9 2 13 19 8 8 27 9 7 2 8 5 25 4 8 8 14 6 9 13 4 8 8 20 14\n" +
                "60 60 6 7 15 27 16 23 9 13 2 9 19 26 12 24 20 27 5 27 2 19 26 26 2 12 12 2 20 9 20 13 28 7 14 18 6 28 19 19 18 15 23 2 27 25 23 7 13 10 6 17 6 18 14 19 19 3 24 20 16 9 19\n" +
                "61 46 5 4 1 4 26 6 19 1 7 16 23 18 0 28 28 10 14 20 7 14 26 9 13 13 23 7 16 6 17 15 16 28 20 9 5 1 16 11 13 23 23 1 4 5 29 0 28 8 0 7 16 21 25 10 6 16 1 4 25 16 21 27\n" +
                "31 12 2 21 22 3 24 3 13 5 1 30 13 2 3 4 2 3 3 10 2 2 3 2 18 2 15 3 2 20 9 25 11 3\n" +
                "2 2 3 7 25\n" +
                "14 1 2 3 0 0 14 3 3 2 30 27 3 3 24 12 13\n" +
                "97 68 0 30 9 5 26 4 19 25 3 14 29 0 0 14 24 25 11 28 2 15 16 20 14 13 18 26 21 11 13 30 3 2 16 11 3 27 7 20 22 15 12 4 8 3 0 5 11 19 4 8 14 17 11 12 18 7 1 17 4 18 12 5 30 28 8 11 23 13 20 5 4 14 24 23 7 0 8 21 23 24 11 19 25 30 10 7 27 9 0 6 3 0 9 8 27 6 19 29\n" +
                "55 1 5 12 11 12 12 12 12 11 12 12 1 12 11 12 12 12 11 8 22 11 26 11 23 30 19 24 12 24 12 7 11 12 6 26 12 11 11 14 12 12 14 18 11 11 8 19 3 12 11 5 12 26 11 11 5 11\n" +
                "64 10 1 29 27 3 26 10 18 12 14 3 5 25 8 25 5 19 24 0 24 27 18 5 8 1 18 18 14 11 12 4 17 0 4 4 29 17 3 27 24 23 23 3 23 23 12 21 18 23 7 21 19 28 0 17 6 4 1 14 27 20 2 4 18 6 26\n" +
                "55 10 6 14 24 14 15 14 10 14 27 15 14 30 15 12 23 15 14 23 15 8 14 6 15 15 25 5 19 25 15 23 15 1 30 14 11 19 3 14 14 27 15 5 15 21 22 14 15 15 15 25 14 14 15 2 15 14\n" +
                "92 92 5 5 21 7 4 10 12 17 16 6 6 8 14 16 21 10 11 5 21 11 21 14 5 18 28 17 9 12 15 3 16 2 3 20 7 8 4 27 5 25 20 23 6 12 6 11 2 16 2 12 23 27 25 10 9 27 15 18 7 22 5 3 15 11 26 21 7 16 5 8 24 20 13 8 3 4 4 9 11 13 28 19 14 20 4 23 25 22 16 28 2 13 4\n" +
                "80 80 5 18 5 11 28 18 16 7 7 15 15 15 13 4 9 23 7 16 8 23 18 6 23 14 12 11 25 25 22 13 11 20 23 18 13 6 25 18 15 10 14 23 27 28 17 24 20 11 14 7 14 11 4 19 25 28 21 5 2 23 13 16 6 4 11 27 21 27 5 3 3 15 23 18 11 4 16 7 22 9 15\n" +
                "81 0 10 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30\n" +
                "64 16 8 20 21 11 6 21 20 20 4 21 20 21 22 17 18 21 26 19 21 1 21 2 21 20 25 21 25 18 21 21 20 27 20 21 28 4 7 17 20 21 22 21 14 14 16 21 21 20 21 21 19 16 16 21 20 21 15 20 20 21 21 4 21 20 7\n" +
                "29 29 9 27 5 13 10 12 5 4 19 18 14 12 3 4 6 5 13 9 24 18 5 13 7 25 4 17 8 5 5 26\n" +
                "59 5 9 10 22 9 24 29 3 24 23 23 8 23 23 7 0 25 22 23 24 23 24 18 23 20 17 23 25 23 23 23 1 30 20 24 23 24 20 24 23 17 23 25 10 7 1 7 23 19 24 23 23 4 13 15 24 23 24 9 24 24\n" +
                "31 20 0 4 29 10 15 7 7 18 28 9 23 9 5 28 6 25 22 24 6 26 5 1 13 22 6 24 4 19 8 13 18 0\n" +
                "72 10 0 19 8 20 24 19 29 5 11 14 15 25 8 6 17 7 29 2 22 13 1 0 25 17 14 7 12 24 30 1 28 1 27 16 22 1 27 8 22 10 12 17 11 6 27 7 11 30 29 22 24 21 21 3 5 9 13 1 3 11 16 8 17 23 11 9 29 30 29 10 24 14 29\n" +
                "89 41 8 26 9 18 10 15 9 9 12 4 19 20 1 24 17 15 6 26 13 15 11 8 0 30 14 29 12 5 20 26 17 26 15 0 18 29 2 13 17 6 24 1 16 11 17 25 26 29 2 10 5 4 22 19 16 10 13 8 12 25 1 26 18 19 30 8 26 22 1 3 16 9 20 1 1 15 28 7 11 25 17 2 17 2 18 24 6 12 6 2\n" +
                "5 0 2 24 9 14 13 29\n" +
                "63 16 4 19 6 20 11 27 23 18 30 1 29 0 0 3 27 25 28 8 7 21 17 22 21 25 23 26 8 0 21 28 11 10 28 9 6 21 17 28 27 12 7 13 27 14 18 7 29 7 17 29 2 16 0 4 15 7 5 6 13 21 27 30 20 18\n" +
                "48 6 10 27 30 27 27 16 27 26 1 7 27 27 24 3 12 26 13 26 24 26 18 13 13 16 26 2 26 27 28 26 18 26 27 27 26 22 9 27 27 0 27 27 27 26 27 26 16 6 27\n" +
                "74 16 2 2 3 3 3 3 3 2 3 3 3 20 2 22 11 3 3 3 3 26 3 3 3 3 3 2 2 3 2 2 6 3 3 2 29 18 2 2 14 3 26 2 3 22 3 2 2 26 26 3 1 30 3 2 6 26 3 10 3 3 30 2 2 6 8 2 2 3 4 2 2 3 9 23 3\n" +
                "66 38 1 9 16 6 7 9 10 5 20 3 15 8 2 23 9 3 7 23 19 25 6 13 9 28 26 11 28 5 4 21 20 18 4 4 27 2 5 30 21 7 10 30 30 1 12 28 6 15 15 30 6 15 6 20 3 27 14 13 27 13 20 7 4 15 17 17 18\n" +
                "16 9 0 25 2 26 4 26 8 23 30 28 23 14 11 20 19 9 11\n" +
                "66 8 5 2 12 11 12 12 21 22 11 13 18 7 8 12 12 22 14 11 11 11 8 29 14 22 20 12 12 9 13 12 28 23 11 12 12 18 12 12 27 19 11 12 6 25 11 11 11 16 15 11 19 12 0 12 19 13 2 20 12 19 2 11 11 19 28 1 12\n" +
                "61 60 1 8 13 24 4 10 22 22 12 12 23 17 15 3 23 18 12 6 8 19 6 22 13 15 19 23 17 3 11 9 9 5 22 26 16 15 24 11 19 11 5 9 9 13 13 25 17 11 24 6 0 18 16 22 21 6 23 15 10 10 2 17\n" +
                "4 4 3 6 20 7 19\n" +
                "30 21 9 19 1 19 12 5 27 14 9 14 13 5 17 25 12 16 29 20 14 28 16 17 21 19 5 30 24 8 11 3 14\n" +
                "4 2 7 15 4 7 19\n" +
                "57 36 4 17 25 2 22 3 21 27 30 16 5 20 29 1 22 19 29 17 0 29 4 26 16 18 22 24 23 29 8 27 20 7 12 1 4 2 24 17 21 1 20 23 20 1 16 11 6 11 16 3 23 27 8 25 22 26 25 10\n" +
                "25 11 2 2 21 2 20 3 26 3 3 0 2 3 12 23 2 3 2 7 2 3 2 26 25 3 2 3\n" +
                "21 5 4 27 19 3 23 29 3 0 13 4 16 29 22 13 13 27 3 25 29 27 16 21\n" +
                "87 25 4 24 13 23 8 22 30 18 11 2 17 23 15 0 21 23 4 7 20 17 12 9 7 14 7 14 17 19 3 15 17 11 20 17 23 4 3 1 24 17 12 18 11 28 17 2 26 16 8 4 1 5 3 2 15 6 17 30 16 9 3 20 17 12 16 6 10 22 2 10 5 23 10 8 0 10 29 17 14 4 9 10 9 15 21 0 30 28\n" +
                "92 26 0 5 1 9 25 5 22 30 3 23 12 12 12 6 10 11 0 21 5 28 6 18 20 22 28 23 22 10 26 25 30 19 10 23 29 22 11 10 6 12 21 16 7 8 28 17 19 18 19 26 25 30 25 3 18 13 24 12 28 15 12 17 16 3 13 9 28 8 12 0 26 22 9 17 17 10 11 22 9 15 25 19 25 18 16 5 6 22 8 22 29 7 19\n" +
                "54 35 10 29 18 8 0 3 20 16 20 6 14 15 12 8 15 13 7 15 13 7 28 2 9 17 3 0 12 27 6 23 4 0 4 2 4 11 6 21 24 2 8 2 4 22 8 15 10 21 23 16 29 13 19 15 3\n" +
                "35 6 2 3 16 3 1 3 3 2 4 13 3 3 3 17 3 27 13 2 3 2 3 29 3 6 3 3 8 18 26 11 17 15 27 8 2 20\n" +
                "50 11 6 2 14 14 15 14 15 22 14 14 14 14 15 10 15 15 8 9 6 26 15 14 15 14 20 15 10 18 15 11 14 1 14 29 14 14 30 6 10 6 18 6 15 30 14 15 14 15 26 19 15\n" +
                "54 37 5 30 14 2 25 10 10 9 0 10 29 9 5 7 14 22 28 27 20 17 8 16 4 12 3 17 29 19 19 6 15 19 22 17 20 14 7 29 10 2 17 5 29 9 28 23 0 2 7 20 11 5 16 17 22\n" +
                "92 63 2 16 23 30 15 21 5 28 8 28 18 4 21 21 7 25 30 9 19 13 7 8 15 9 5 22 26 22 16 18 29 18 23 11 7 18 6 11 3 14 1 29 2 4 4 24 19 2 28 26 0 13 27 12 17 22 0 12 15 21 22 6 20 11 4 20 16 1 23 24 3 1 4 30 21 12 23 19 15 16 25 17 23 8 19 8 16 2 13 4 22 25 16\n" +
                "66 35 4 30 9 8 9 9 8 24 9 8 2 27 18 15 8 27 18 8 9 27 19 13 8 8 8 27 12 8 5 9 9 9 16 21 9 8 8 6 9 10 0 28 8 8 5 8 8 9 14 9 1 8 8 8 9 9 15 8 9 8 8 1 8 8 18 3 8\n" +
                "64 24 2 22 9 7 2 28 3 3 3 14 28 2 29 3 4 6 3 3 3 2 23 30 3 3 3 2 14 2 13 5 30 2 3 10 3 2 2 13 3 21 3 20 3 10 13 3 3 8 3 26 3 3 29 2 5 24 3 3 2 8 3 5 3 27 3\n" +
                "65 41 5 0 8 21 1 19 27 21 27 0 15 28 29 25 15 15 4 17 20 27 29 15 17 21 16 18 14 23 24 20 22 15 13 10 27 10 15 27 8 4 0 17 24 18 0 30 17 29 24 15 17 14 2 21 0 4 16 13 22 24 12 12 1 6 13 14\n" +
                "38 12 6 13 9 19 26 15 18 28 2 1 7 4 4 30 10 13 27 17 23 0 22 4 30 17 22 17 27 26 24 6 13 29 9 30 11 5 9 22 0\n" +
                "54 4 1 15 12 11 0 28 22 24 14 30 26 25 1 10 23 21 16 24 6 13 12 1 24 2 17 22 27 18 14 3 4 13 23 7 23 22 30 12 19 14 10 2 13 5 2 12 27 17 21 22 20 23 4 13 25\n" +
                "5 1 5 12 8 11 5 23\n" +
                "69 23 10 13 10 0 7 19 16 23 16 1 2 17 23 8 23 1 28 3 0 24 13 23 20 28 30 30 26 9 27 10 13 27 6 6 30 19 13 9 22 16 0 10 12 17 24 15 3 24 15 20 3 17 2 28 15 11 15 25 5 21 19 0 0 18 13 5 9 24 20 14\n" +
                "95 32 5 6 12 18 25 11 12 21 12 11 13 11 24 23 10 30 21 2 12 0 11 11 12 12 11 28 12 29 4 26 12 0 11 25 24 12 12 22 12 6 6 12 28 6 28 12 12 21 11 12 19 11 11 11 12 7 11 11 8 16 11 11 11 11 15 18 12 12 3 2 2 11 12 24 11 6 11 3 11 11 12 12 12 12 11 12 14 1 14 30 12 11 2 11 28 29\n" +
                "79 42 5 20 3 13 1 5 21 4 0 25 25 19 23 24 18 26 7 24 15 8 0 3 5 7 13 30 18 5 16 28 11 25 16 16 28 8 5 18 23 1 29 7 0 14 7 10 14 12 26 17 11 23 21 11 19 30 5 21 18 9 1 30 4 11 18 25 10 11 27 17 27 11 20 24 20 29 10 11 8 20\n" +
                "8 5 2 0 6 26 20 27 6 15 29\n" +
                "80 80 4 28 28 4 10 28 26 4 3 17 24 7 11 15 3 27 6 26 22 8 2 4 25 7 9 17 24 25 12 8 17 20 12 20 12 16 19 2 22 16 14 16 26 15 21 17 27 20 12 9 17 3 26 28 27 4 11 25 8 24 3 15 15 15 17 21 8 23 6 15 3 21 7 6 2 11 21 9 10 18 16\n" +
                "72 58 9 30 0 27 26 13 2 10 14 25 6 23 13 23 5 18 26 27 1 16 4 18 7 8 13 25 12 11 23 5 16 5 5 30 13 24 22 22 14 15 28 11 21 3 12 19 8 21 21 23 13 30 5 11 29 16 12 28 23 28 8 10 26 21 15 16 22 22 13 30 30 28 9\n" +
                "72 5 3 24 27 19 5 5 7 6 28 6 26 8 5 5 23 6 25 10 29 7 5 25 15 5 5 5 6 5 5 5 5 5 5 5 5 6 6 29 6 22 5 29 6 25 9 12 6 6 6 6 30 5 12 6 16 5 6 5 0 14 5 5 6 1 5 1 8 5 14 12 6 4 27\n" +
                "41 41 5 28 7 25 27 27 24 19 26 20 14 9 9 27 6 16 20 26 10 19 26 20 14 18 19 16 27 24 22 21 5 5 10 10 10 2 10 17 5 13 7 17\n" +
                "33 0 2 0 14 12 16 29 11 23 2 30 29 28 16 15 3 18 17 11 20 24 17 23 7 12 26 2 22 13 2 7 19 21 18 11\n" +
                "82 82 4 5 22 2 28 6 6 25 28 10 13 25 4 26 2 14 17 19 14 16 24 19 27 8 27 15 5 11 14 28 28 27 5 9 15 3 7 22 12 27 24 25 18 4 23 28 13 26 19 19 18 10 11 3 17 13 2 14 22 8 16 11 2 22 26 27 6 4 26 13 13 9 13 18 24 17 16 16 2 27 6 10 19\n" +
                "34 0 7 6 8 10 12 26 21 14 21 15 25 29 5 20 22 17 7 9 14 4 30 25 11 17 28 0 28 1 19 3 13 20 25 7 16\n" +
                "100 33 0 16 27 2 27 28 20 1 7 11 7 14 25 4 10 20 28 13 27 26 23 17 27 21 1 2 7 23 11 12 12 7 11 18 29 17 3 27 28 11 28 24 26 20 28 18 2 23 13 18 25 29 24 0 25 21 8 0 20 16 10 23 15 2 1 22 23 6 1 26 22 10 20 13 26 22 30 16 15 16 11 7 28 29 13 8 22 28 17 5 7 12 22 10 20 30 26 23 24 5 7\n" +
                "17 0 8 21 20 21 20 21 20 20 21 21 20 20 20 20 13 29 11 21\n" +
                "58 0 4 3 1 19 28 19 6 5 19 24 13 7 12 2 29 24 10 6 28 19 3 10 0 16 29 1 4 12 5 11 10 14 8 22 20 1 5 14 3 0 0 12 6 5 14 13 12 3 23 13 4 15 13 20 1 23 9 21 2\n" +
                "8 6 8 22 18 14 29 10 17 16 13\n" +
                "18 8 8 27 6 18 21 26 27 6 21 20 20 20 20 20 4 21 21 16 20\n" +
                "38 0 7 17 16 25 16 23 22 26 26 28 22 18 27 17 17 12 14 25 22 12 8 28 4 15 24 11 15 6 12 17 29 18 9 27 15 4 2 0 9\n" +
                "97 0 7 11 20 2 13 7 30 30 21 8 20 0 5 11 24 4 27 29 30 25 7 21 15 2 8 26 22 17 17 1 24 9 20 24 10 14 10 4 29 18 19 25 4 13 7 16 16 11 22 17 4 16 25 3 22 10 15 5 27 25 10 18 21 11 23 21 24 16 10 15 15 22 7 5 1 10 3 25 17 29 15 11 26 2 2 8 15 7 23 27 16 24 19 6 24 18 1 15\n" +
                "77 0 1 12 17 27 13 9 19 9 3 11 8 18 19 4 28 26 1 7 15 0 6 11 3 7 1 4 16 25 19 1 7 11 9 26 6 6 3 23 30 4 7 28 20 22 5 19 9 25 15 23 7 29 20 7 29 27 30 23 18 17 17 1 28 0 21 24 17 0 9 17 25 1 13 1 29 10 25 24\n" +
                "88 64 8 17 1 3 1 3 1 9 26 27 3 3 9 30 10 23 10 15 26 7 7 21 22 0 4 29 0 16 8 28 1 9 7 3 23 25 17 7 30 23 30 11 15 1 1 7 0 26 14 11 3 20 8 12 24 24 0 13 27 27 12 1 6 3 18 12 26 6 15 30 15 2 25 19 3 11 16 9 2 8 22 16 26 10 0 9 23 23 2\n" +
                "68 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
                "70 23 4 13 30 2 9 30 9 22 9 8 8 14 27 8 13 9 8 8 28 22 8 0 8 8 18 9 18 9 8 9 22 8 20 8 30 8 19 8 9 20 8 9 2 15 9 7 14 17 17 25 8 9 13 18 9 9 9 8 24 8 8 6 7 3 9 9 8 10 4 8 9\n" +
                "48 15 1 3 1 12 7 4 5 27 30 8 5 11 8 10 20 14 25 28 13 20 1 14 25 11 30 12 4 14 27 4 9 0 22 30 4 19 0 24 11 8 3 1 12 30 17 20 2 23 12\n" +
                "84 84 10 12 23 12 20 28 6 16 5 28 21 13 13 15 14 25 17 23 28 12 13 27 15 14 7 5 15 16 5 13 17 23 10 23 12 9 6 21 3 21 6 17 17 15 2 27 5 19 12 10 18 15 20 2 25 15 10 9 5 13 13 18 9 19 9 2 14 6 26 22 10 25 4 27 28 16 13 6 6 27 23 12 17 10 23\n" +
                "78 78 1 10 3 4 10 3 2 8 3 11 15 12 19 9 28 4 7 22 19 16 26 18 12 16 26 21 4 23 20 18 26 20 16 23 7 17 14 13 26 9 13 19 26 15 13 26 25 26 23 23 9 28 8 28 16 18 23 17 11 8 28 20 4 13 10 6 5 27 17 11 26 6 21 10 28 13 7 8 11\n" +
                "26 26 7 4 6 9 15 4 21 18 6 4 3 10 15 7 3 13 8 10 21 11 12 10 4 16 3 11 6\n" +
                "95 0 6 4 5 30 28 18 26 13 15 20 14 18 16 21 6 29 17 1 0 9 25 11 30 28 27 5 27 8 15 1 17 11 28 20 5 2 27 6 24 13 28 13 21 23 14 13 30 9 12 26 13 15 12 29 28 24 26 3 27 15 20 3 18 2 22 23 16 3 23 14 24 18 0 8 0 26 2 14 26 15 19 28 26 0 22 25 19 13 28 27 5 21 30 22 18 13\n" +
                "39 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
                "65 6 2 2 2 11 3 3 2 2 2 22 16 23 6 2 23 2 3 2 2 2 25 14 3 21 2 3 28 2 2 21 3 30 2 2 4 2 10 20 2 28 11 15 3 14 9 14 3 6 3 2 12 3 2 6 2 20 17 2 2 1 3 9 3 12 14 3\n" +
                "12 1 7 18 18 15 17 17 18 17 13 17 17 15 17\n" +
                "55 34 6 3 27 20 27 14 15 14 22 5 5 1 12 30 12 20 19 6 6 20 21 11 28 0 23 8 28 11 27 19 26 13 1 19 0 9 14 17 12 2 4 13 11 29 25 0 23 22 9 24 27 16 26 10 17 14\n" +
                "32 8 6 14 15 18 2 14 14 26 14 18 8 23 13 9 26 7 15 15 15 15 15 15 14 24 14 17 14 16 14 27 15 14 21\n" +
                "1 0 9 17\n" +
                "51 8 8 30 15 7 26 0 5 1 20 5 10 5 18 14 1 27 29 20 13 23 25 7 11 18 6 9 19 14 18 14 28 18 20 3 18 20 20 6 5 21 17 24 28 27 17 14 15 7 3 15 22 25\n" +
                "82 0 0 6 0 18 22 5 19 0 28 3 11 6 23 15 9 19 24 3 29 25 0 4 3 19 29 24 6 21 2 14 23 5 6 15 23 3 24 13 4 4 17 30 25 12 7 9 27 11 10 2 8 0 21 29 25 21 3 0 20 15 4 2 14 15 1 9 24 1 9 13 30 23 22 14 11 21 5 1 25 4 7 27 15\n" +
                "93 4 3 18 5 0 5 22 19 6 17 5 6 5 5 15 6 6 6 26 6 9 6 12 6 5 6 6 25 5 14 5 30 5 5 21 28 19 26 6 5 5 5 21 6 5 23 10 6 5 5 17 16 5 11 6 5 6 25 14 23 5 2 6 6 6 6 6 11 13 6 6 5 23 5 5 5 5 5 6 5 21 6 6 6 5 9 21 8 6 21 2 18 5 6 27\n" +
                "98 11 8 24 1 3 13 17 1 15 2 0 30 2 13 12 5 12 6 17 10 19 30 1 2 19 24 5 21 26 26 26 1 2 10 9 19 7 17 19 20 18 4 3 13 12 30 8 27 22 26 16 17 30 11 9 7 16 27 0 18 22 22 19 2 10 24 30 28 27 30 24 14 11 21 19 0 3 1 3 14 18 19 26 10 14 29 8 11 23 9 28 23 16 29 16 3 7 22 17 14\n" +
                "9 9 3 16 5 2 20 13 27 12 10 14\n" +
                "49 8 10 21 2 19 26 26 30 18 21 27 11 5 17 1 26 22 27 22 2 27 27 26 10 29 11 16 26 27 12 23 27 21 27 27 27 27 13 17 15 27 2 13 27 26 2 9 26 27 21 26\n" +
                "43 24 3 26 25 19 28 11 10 15 25 20 17 24 4 8 26 0 23 12 10 29 12 6 14 6 21 6 19 19 27 30 5 24 10 13 12 23 21 16 30 13 20 15 11 11\n" +
                "21 2 2 2 14 18 12 2 3 3 3 2 3 3 1 29 0 14 7 2 3 10 21 3\n" +
                "22 2 2 2 2 2 19 2 28 10 14 3 2 8 3 23 3 14 2 2 3 2 17 2 20\n" +
                "1 1 3 13\n" +
                "64 16 3 6 5 5 7 13 6 20 22 7 17 6 30 6 16 5 19 5 6 6 25 23 6 18 5 11 3 6 6 8 5 22 5 6 5 20 10 29 30 6 5 5 27 22 29 5 5 27 5 0 30 16 18 28 7 14 8 6 10 5 16 18 25 13 5\n";

        System.out.println(executeTestCase(input));

        

    }

    private static String executeTestCase(String input) {

        String strOutput = "";
        BufferedReader in = new BufferedReader(new StringReader(input));
        int testCases = 0;
        try {
            testCases = Integer.valueOf(in.readLine());
        } catch (IOException e) {
            return "Invalid test case input at line 1";
        }

        try {
            if (testCases > 0) {
                for (int i = 1; i <= testCases; i++) {
                    String lines[] = in.readLine().split(" ");
                    int numberOfGooglers = Integer.valueOf(lines[0]);
                    int numberOfSurprising = Integer.valueOf(lines[1]);
                    int target = Integer.valueOf(lines[2]);
                    List<Integer> lst = new ArrayList<Integer>();
                    if(numberOfGooglers > 0) {
                        for(int j=0; j< numberOfGooglers; j++) {
                            lst.add(Integer.valueOf(lines[j+3]));
                        }
                    }
                    strOutput+="Case #" + i + ": " + countGooglersByTarget(target, numberOfSurprising, lst) + "\n";
                }
            }
        } catch (Exception e) {
            return "Invalid test case input";
        }

        return strOutput.toString();

    }

}
