package template;

import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;

public class TestCase {

    private boolean isSolved;
    private Object solution;
    private Map<String, Integer> intProperties;
    private Map<String, ArrayList<Integer>> intArrayProperties;
    private Map<String, ArrayList<ArrayList<Integer>>> intArray2DProperties;
    private Map<String, Double> doubleProperties;
    private Map<String, ArrayList<Double>> doubleArrayProperties;
    private Map<String, ArrayList<ArrayList<Double>>> doubleArray2DProperties;
    private Map<String, String> stringProperties;
    private Map<String, ArrayList<String>> stringArrayProperties;
    private Map<String, ArrayList<ArrayList<String>>> stringArray2DProperties;
    private Map<String, Boolean> booleanProperties;
    private Map<String, ArrayList<Boolean>> booleanArrayProperties;
    private Map<String, ArrayList<ArrayList<Boolean>>> booleanArray2DProperties;
    private Map<String, Long> longProperties;
    private Map<String, ArrayList<Long>> longArrayProperties;
    private Map<String, ArrayList<ArrayList<Long>>> longArray2DProperties;
    private int ref;
    private double time;

    public TestCase() {
        initialise();
    }

    private void initialise() {
        isSolved = false;
        intProperties = new HashMap<>();
        intArrayProperties = new HashMap<>();
        intArray2DProperties = new HashMap<>();
        doubleProperties = new HashMap<>();
        doubleArrayProperties = new HashMap<>();
        doubleArray2DProperties = new HashMap<>();
        stringProperties = new HashMap<>();
        stringArrayProperties = new HashMap<>();
        stringArray2DProperties = new HashMap<>();
        booleanProperties = new HashMap<>();
        booleanArrayProperties = new HashMap<>();
        booleanArray2DProperties = new HashMap<>();
        longProperties = new HashMap<>();
        longArrayProperties = new HashMap<>();
        longArray2DProperties = new HashMap<>();
        ref = 0;
    }

    public void setSolution(Object o) {
        solution = o;
        isSolved = true;
    }
    
    public Object getSolution() {
        if (!isSolved) {
            Utils.die("getSolution on unsolved testcase");
        }

        return solution;
    }

    public void setRef(int i) {
        ref = i;
    }
    public int getRef() {
        return ref;
    }

    public void setTime(double d) {
        time = d;
    }
    public double getTime() {
        return time;
    }
    
    public void setInteger(String s, Integer i) {
        intProperties.put(s, i);
    }
    
    public Integer getInteger(String s) {
        return intProperties.get(s);
    }

    public void setIntegerList(String s, ArrayList<Integer> l) {
        intArrayProperties.put(s, l);
    }

    public void setIntegerMatrix(String s, ArrayList<ArrayList<Integer>> l) {
        intArray2DProperties.put(s, l);
    }

    public ArrayList<Integer> getIntegerList(String s) {
        return intArrayProperties.get(s);
    }

    public Integer getIntegerListItem(String s, int i) {
        return intArrayProperties.get(s).get(i);
    }

    public ArrayList<ArrayList<Integer>> getIntegerMatrix(String s) {
        return intArray2DProperties.get(s);
    }
    
    public ArrayList<Integer> getIntegerMatrixRow(String s, int row) {
        return intArray2DProperties.get(s).get(row);
    }
    
    public Integer getIntegerMatrixItem(String s, int row, int column) {
        return intArray2DProperties.get(s).get(row).get(column);
    }

    public ArrayList<Integer> getIntegerMatrixColumn(String s, int column) {
        ArrayList<Integer> out = new ArrayList();
        
        for(ArrayList<Integer> row : intArray2DProperties.get(s)) {
            out.add(row.get(column));
        }
        return out;
    }


    public void setDouble(String s, Double i) {
        doubleProperties.put(s, i);
    }
    
    public Double getDouble(String s) {
        return doubleProperties.get(s);
    }

    public void setDoubleList(String s, ArrayList<Double> l) {
        doubleArrayProperties.put(s, l);
    }

    public void setDoubleMatrix(String s, ArrayList<ArrayList<Double>> l) {
        doubleArray2DProperties.put(s, l);
    }

    public ArrayList<Double> getDoubleList(String s) {
        return doubleArrayProperties.get(s);
    }

    public Double getDoubleListItem(String s, int i) {
        return doubleArrayProperties.get(s).get(i);
    }

    public ArrayList<ArrayList<Double>> getDoubleMatrix(String s) {
        return doubleArray2DProperties.get(s);
    }
    
    public ArrayList<Double> getDoubleMatrixRow(String s, int row) {
        return doubleArray2DProperties.get(s).get(row);
    }
    
    public Double getDoubleMatrixItem(String s, int row, int column) {
        return doubleArray2DProperties.get(s).get(row).get(column);
    }

    public ArrayList<Double> getDoubleMatrixColumn(String s, int column) {
        ArrayList<Double> out = new ArrayList();
        
        for(ArrayList<Double> row : doubleArray2DProperties.get(s)) {
            out.add(row.get(column));
        }
        return out;
    }

    
    public void setString(String s, String t) {
        stringProperties.put(s, t);
    }
    
    public String getString(String s) {
        return stringProperties.get(s);
    }

    public void setStringList(String s, ArrayList<String> l) {
        stringArrayProperties.put(s, l);
    }

    public void setStringMatrix(String s, ArrayList<ArrayList<String>> l) {
        stringArray2DProperties.put(s, l);
    }

    public ArrayList<String> getStringList(String s) {
        return stringArrayProperties.get(s);
    }

    public String getStringListItem(String s, int i) {
        return stringArrayProperties.get(s).get(i);
    }

    public ArrayList<ArrayList<String>> getStringMatrix(String s) {
        return stringArray2DProperties.get(s);
    }
    
    public ArrayList<String> getStringMatrixRow(String s, int row) {
        return stringArray2DProperties.get(s).get(row);
    }
    
    public String getStringMatrixItem(String s, int row, int column) {
        return stringArray2DProperties.get(s).get(row).get(column);
    }

    public ArrayList<String> getStringMatrixColumn(String s, int column) {
        ArrayList<String> out = new ArrayList();
        
        for(ArrayList<String> row : stringArray2DProperties.get(s)) {
            out.add(row.get(column));
        }
        return out;
    }

    
    public void setBoolean(String s, Boolean b) {
        booleanProperties.put(s, b);
    }
    
    public Boolean getBoolean(String s) {
        return booleanProperties.get(s);
    }

    public void setBooleanList(String s, ArrayList<Boolean> l) {
        booleanArrayProperties.put(s, l);
    }

    public void setBooleanMatrix(String s, ArrayList<ArrayList<Boolean>> l) {
        booleanArray2DProperties.put(s, l);
    }

    public ArrayList<Boolean> getBooleanList(String s) {
        return booleanArrayProperties.get(s);
    }

    public Boolean getBooleanListItem(String s, int i) {
        return booleanArrayProperties.get(s).get(i);
    }

    public ArrayList<ArrayList<Boolean>> getBooleanMatrix(String s) {
        return booleanArray2DProperties.get(s);
    }
    
    public ArrayList<Boolean> getBooleanMatrixRow(String s, int row) {
        return booleanArray2DProperties.get(s).get(row);
    }
    
    public Boolean getBooleanMatrixItem(String s, int row, int column) {
        return booleanArray2DProperties.get(s).get(row).get(column);
    }

    public ArrayList<Boolean> getBooleanMatrixColumn(String s, int column) {
        ArrayList<Boolean> out = new ArrayList();
        
        for(ArrayList<Boolean> row : booleanArray2DProperties.get(s)) {
            out.add(row.get(column));
        }
        return out;
    }

    public void setLong(String s, Long b) {
        longProperties.put(s, b);
    }
    
    public Long getLong(String s) {
        return longProperties.get(s);
    }

    public void setLongList(String s, ArrayList<Long> l) {
        longArrayProperties.put(s, l);
    }

    public void setLongMatrix(String s, ArrayList<ArrayList<Long>> l) {
        longArray2DProperties.put(s, l);
    }

    public ArrayList<Long> getLongList(String s) {
        return longArrayProperties.get(s);
    }

    public Long getLongListItem(String s, int i) {
        return longArrayProperties.get(s).get(i);
    }

    public ArrayList<ArrayList<Long>> getLongMatrix(String s) {
        return longArray2DProperties.get(s);
    }
    
    public ArrayList<Long> getLongMatrixRow(String s, int row) {
        return longArray2DProperties.get(s).get(row);
    }
    
    public Long getLongMatrixItem(String s, int row, int column) {
        return longArray2DProperties.get(s).get(row).get(column);
    }

    public ArrayList<Long> getLongMatrixColumn(String s, int column) {
        ArrayList<Long> out = new ArrayList();
        
        for(ArrayList<Long> row : longArray2DProperties.get(s)) {
            out.add(row.get(column));
        }
        return out;
    }

    

    


}

import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;

public class bx{
	public static void main(String[] args){
		try{			
			File output;
			FileWriter outputwriter;
			BufferedWriter out;
			String filename = "bx.out";
			
			output = new File(filename);
			outputwriter = new FileWriter(output);
			out = new BufferedWriter(outputwriter);
			
			//System.out.println("siap");
			//out.write("ardhianvv\nll");
			BufferedReader f = new BufferedReader(new FileReader("a.in"));
			StringTokenizer st = new StringTokenizer(f.readLine());
			int datax[][] = new int[][]{{0, 0, 0, 0,0},
{1, 0, 0, 1,0},
{10, 2, 4, 4,1},
{10, 3, 3, 4,0},
{11, 3, 3, 5,1},
{11, 3, 4, 4,0},
{12, 3, 4, 5,1},
{12, 4, 4, 4,0},
{13, 3, 5, 5,1},
{13, 4, 4, 5,0},
{14, 4, 4, 6,1},
{14, 4, 5, 5,0},
{15, 4, 5, 6,1},
{15, 5, 5, 5,0},
{16, 4, 6, 6,1},
{16, 5, 5, 6,0},
{17, 5, 5, 7,1},
{17, 5, 6, 6,0},
{18, 5, 6, 7,1},
{18, 6, 6, 6,0},
{19, 5, 7, 7,1},
{19, 6, 6, 7,0},
{2, 0, 0, 2,1},
{2, 0, 1, 1,0},
{20, 6, 6, 8,1},
{20, 6, 7, 7,0},
{21, 6, 7, 8,1},
{21, 7, 7, 7,0},
{22, 6, 8, 8,1},
{22, 7, 7, 8,0},
{23, 7, 7, 9,1},
{23, 7, 8, 8,0},
{24, 7, 8, 9,1},
{24, 8, 8, 8,0},
{25, 7, 9, 9,1},
{25, 8, 8, 9,0},
{26, 8, 8, 10,1},
{26, 8, 9, 9,0},
{27, 8, 9, 10,1},
{27, 9, 9, 9,0},
{28, 8, 10, 10,1},
{28, 9, 9, 10,0},
{29, 9, 10, 10,0},
{3, 0, 1, 2,1},
{3, 1, 1, 1,0},
{30, 10, 10, 10,0},
{4, 0, 2, 2,1},
{4, 1, 1, 2,0},
{5, 1, 1, 3,1},
{5, 1, 2, 2,0},
{6, 1, 2, 3,1},
{6, 2, 2, 2,0},
{7, 1, 3, 3,1},
{7, 2, 2, 3,0},
{8, 2, 2, 4,1},
{8, 2, 3, 3,0},
{9, 2, 3, 4,1},
{9, 3, 3, 3,0}
};
			int angka = Integer.parseInt(st.nextToken());
			for(int a=0;a<angka;a++){
				st = new StringTokenizer(f.readLine());
				String hh[] = st.nextToken("\n").split(" ");
				int n = Integer.parseInt(hh[0]);
				maxS = Integer.parseInt(hh[1]);
				minP = Integer.parseInt(hh[2]);
				maxx = 0;
				int ss[] = new int[n];
				ssx = new int[n][2][5];
				sx = new int[n];
				int gaDa = 0;
				for(int b=0;b<n;b++){
					ss[b] = Integer.parseInt(hh[3+b]);
					ssx[b][0][4] = ss[b];
					ssx[b][1][4] = ss[b];
					int ind =0;
					for(int c=0;c<datax.length;c++){
						if(datax[c][0]==ss[b]){
							ssx[b][ind][0] = datax[c][1];
							ssx[b][ind][1] = datax[c][2];
							ssx[b][ind][2] = datax[c][3];
							ssx[b][ind][3] = datax[c][4];														
							ind++;
						}
					}
				}
				
				if(a==0)
				for(int b=0;b<ssx.length;b++){
					for(int c=0;c<2;c++){
						System.out.println(ssx[b][c][0]+" "+ssx[b][c][1]+" "+ssx[b][c][2]+" "+ssx[b][c][3]+" "+ssx[b][c][4]);
					}
					System.out.println();
				}
				if(gaDa==0)
					find(0,0, new int[n][3]);
				if(a!=angka-1)					
					out.write("Case #"+(a+1)+": "+maxx+"\n");
				else
					out.write("Case #"+(a+1)+": "+maxx);
			}
			out.close();
		} catch(Exception cc){
			System.out.println(cc.toString());
		}
	}
	public static void find(int ind, int s, int data[][]){
		if(s==maxS){			
			for(int a=ind;a<data.length;a++){
				for(int c=0;c<ssx[a].length;c++)
					if(ssx[a][c][3]==0)
						if(ssx[a][c][0]+ssx[a][c][1]+ssx[a][c][2]==ssx[a][c][4]){
							data[a][0] = ssx[a][c][0];
							data[a][1] = ssx[a][c][1];
							data[a][2] = ssx[a][c][2];
						}				
			}
			System.out.println("+");
			for(int b=0;b<data.length;b++){
				System.out.println(data[b][0]+" "+data[b][1]+" "+data[b][2]);
			}
			System.out.println("-");
			maxx = Math.max(maxx,hitung(data));
		} else if(s<maxS && ind<data.length){
			if(ssx[ind][0][0]+ssx[ind][0][1]+ssx[ind][0][2]==ssx[ind][0][4]){
				data[ind][0] = ssx[ind][0][0];
				data[ind][1] = ssx[ind][0][1];
				data[ind][2] = ssx[ind][0][2];
				if(ssx[ind][0][3]==0)
					find(ind+1, s,data);
				else
					find(ind+1, s+1,data);
			}
			if(ssx[ind][1][0]+ssx[ind][1][1]+ssx[ind][1][2]==ssx[ind][1][4]){
				data[ind][0] = ssx[ind][1][0];
				data[ind][1] = ssx[ind][1][1];
				data[ind][2] = ssx[ind][1][2];
				if(ssx[ind][1][3]==0)
					find(ind+1, s,data);
				else
					find(ind+1, s+1,data);
			}
		}
	}
	public static int hitung(int [][] data){
		int hasil =0;
		for(int a=0;a<data.length;a++){
			if(data[a][0]>=minP || data[a][1]>=minP || data[a][2]>=minP){
				hasil++;
			}
		}
		return hasil;
	}
	public static int maxS = 0;
	public static int minP = 0;
	public static int maxx = 0;
	public static int ssx[][][] = new int[1][1][1];
	public static int sx[] = new int[1];
}