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 ? " *" : ""));
//    }
    
}

import com.sun.org.apache.xerces.internal.impl.xs.opti.DefaultXMLDocumentHandler;
import util.graph.DynDjikstra;
import util.graph.Edge;
import util.graph.Node;
import util.graph.State;

import javax.xml.crypto.dsig.CanonicalizationMethod;
import java.io.IOException;
import java.math.BigInteger;
import java.util.List;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.TreeSet;

public class CrossingRoad extends JamProblem {

    public static void main(String[] args) throws IOException {
        CrossingRoad p = new CrossingRoad();
        p.go();
    }
    @Override
    String solveCase(JamCase jamCase) {
        CrossCase ca = (CrossCase) jamCase;
        CrossState crossState = new CrossState();
        crossState.time = 0;
        ca.startNode.last = crossState;
        CrossState state = (CrossState) DynDjikstra.FindShortest(ca.startNode, ca.stopNode);


        return "" + state.time;
    }

    @Override
    JamCase parseCase(List<String> file, int line) {
        String first = file.get(line++);
        int[] size = JamUtil.parseIntList(first, 2);
        CrossCase ca = new CrossCase();
        ca.n = size[0];
        ca.m = size[1];
        ca.lineCount = ca.n + 1;
        ca.map = new Crossing[ca.n][ca.m];
        Node[][][][] nodes = new Node[ca.n][ca.m][2][2];
        Node start = null;
        Node end = null;
        for (int y = 0; y < ca.n; y++) {
            String row = file.get(line++);
            int[] data = JamUtil.parseIntList(row, 3 * ca.m);
            for (int x = 0; x < ca.m; x++) {
                Crossing cr = new Crossing();
                ca.map[y][x] = cr;
                cr.minTime = Integer.MAX_VALUE;
                cr.s = data[3*x];
                cr.w = data[3*x+1];
                cr.t = data[3*x+2];
                cr.x = x;
                cr.y = y;
                Node ne = new CrossNode();

                Node se = new CrossNode();
                Node sw = new CrossNode();
                Node nw = new CrossNode();
                CrossStreetSNEdge snEdge1 = new CrossStreetSNEdge();
                snEdge1.s =cr.s;
                snEdge1.w = cr.w;
                snEdge1.t = cr.t;
                CrossStreetWEEdge weEdge = new CrossStreetWEEdge();
                weEdge.s= cr.s;
                weEdge.w=cr.w;
                weEdge.t=cr.t;

                snEdge1.biConnect(ne,se);
                snEdge1.biConnect(nw,sw);
                weEdge.biConnect(ne,nw);
                weEdge.biConnect(se,sw);

                Node[][] pack = nodes[y][x];
                pack[0][0] = nw;
                pack[0][1] = ne;
                pack[1][1] = se;
                pack[1][0] = sw;
                ((CrossNode)nw).label = "y " + y + " x " + x + " nw";
                ((CrossNode)ne).label = "y " + y + " x " + x + " ne";
                ((CrossNode)se).label = "y " + y + " x " + x + " se";
                ((CrossNode)sw).label = "y " + y + " x " + x + " sw";
                if (y==0 && x ==ca.m-1) {
                    ca.stopNode = pack[0][1];
                }

                if (y==ca.n-1 && x == 0) {
                    ca.startNode = pack[1][0];
                }

                if (y>0) {
                    CrossBlockEdge b1 = new CrossBlockEdge();
                    b1.biConnect(nodes[y][x][0][1],nodes[y-1][x][1][1]);
                    b1.biConnect(nodes[y][x][0][0],nodes[y-1][x][1][0]);
                }

                if (x>0) {
                    CrossBlockEdge b1 = new CrossBlockEdge();
                    b1.biConnect(nodes[y][x][0][0], nodes[y][x - 1][0][1]);
                    b1.biConnect(nodes[y][x][1][0],nodes[y][x-1][1][1]);
                }
            }
        }
        return ca;
    }
}

class CrossCase extends JamCase {
    int n, m;
    Crossing[][] map;
    public Node startNode;
    public Node stopNode;
}

class Crossing implements Comparable<Crossing>{
    int s, w, t, minTime,x,y;

    @Override
    public int compareTo(Crossing o) {
        return Integer.compare(minTime,o.minTime);
    }
}

class CrossState extends State {

    long time;
    @Override
    public int compareTo(Object o) {
        return Long.compare(time,((CrossState)o).time);
    }
}

class CrossBlockEdge extends Edge {
    @Override
    public State travel(State current) {
        CrossState old = (CrossState) current;
        CrossState newS = new CrossState();
        newS.time = old.time + 2;
        return newS;
    }
}

class CrossStreetSNEdge extends Edge {
    long s,w,t;
    @Override
    public State travel(State current) {
        CrossState old = (CrossState) current;
        CrossState newS = new CrossState();
        long adjusted = old.time - t;
        long period = s + w;
        long inCycle = adjusted % period;
        if (inCycle < s) {
            newS.time = old.time + 1;
            return newS;
        }
        newS.time = old.time + (period-inCycle);
        return newS;
    }
}

class CrossStreetWEEdge extends Edge {
    long s,w,t;
    @Override
    public State travel(State current) {
        CrossState old = (CrossState) current;
        CrossState newS = new CrossState();
        long adjusted = old.time - t;
        long period = s + w;
        long inCycle = adjusted % period;
        if (inCycle >= s) {
            newS.time = old.time + 1;
            return newS;
        }
        newS.time = old.time + (s-inCycle);
        return newS;
    }
}

class CrossNode extends Node {
    String label;
    CrossNode() {
        last = new CrossState();
    }

    @Override
    public String toString() {
        return label;
    }
}
