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;
    }

    

    


}

/**
 * Created by IntelliJ IDEA.
 * User: kingsto
 * Date: 4/14/12
 * Time: 10:14 PM
 * To change this template use File | Settings | File Templates.
 */
// to be run with -Xmx1024m

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

public class DancingWithGooglers {

    class Testcase {
        int ans;
        int[][][] hello = new int[30][][];

        public Testcase() {
        }

        public Testcase(int seed) {
            Random rnd = new Random(seed);
        }

        int N, S, P;
        int[][] ns, s;
        int[] scores;
        boolean[] selected;
        public void loadInput(Scanner sc, int[][] _ns, int[][] _s) {
            N = sc.nextInt();
            S = sc.nextInt();
            P = sc.nextInt();
            scores = new int[N];
            selected = new boolean[N];
            ns = _ns;
            s = _s;
            
            for (int i = 0; i < N; i++) {
                scores[i] = sc.nextInt();
            }
        }

        public void solveSlow() {
            int res = 0;
            if (S == 0) {
                for (int i = 0; i < N; i++) {
                    int[] sc = supporting[scores[i]];
                    if (sc[0] >= P || sc[1] >= P || sc[2] >= P)  res++;
                }
                ans = res;
            }
            if (S == 1) {
                for (int i = 0; i < N; i++) {
                    res = 0;
                    int[] nsc = nsupporting[scores[i]];
                    if (nsc[0] < 0) nsc = supporting[scores[i]];
                    if (nsc[0] >= P || nsc[1] >= P || nsc[2] >= P)  res++;
                    for (int j = 0; j < N ; j++ ) {
                        if (j != i) {
                            int[] sc = supporting[scores[j]];
                            if (sc[0] >= P || sc[1] >= P || sc[2] >= P)  res++;
                        }
                    }
                    ans = Math.max(res, ans);
                }
            }
            if (S == 2) {
                for (int i = 0; i < N; i++) {
                    res = 0;
                    int[] nsc = nsupporting[scores[i]];
                    if (nsc[0] < 0) nsc = supporting[scores[i]];
                    if (nsc[0] >= P || nsc[1] >= P || nsc[2] >= P)  res++;
                    for (int j = 0; j < N ; j++ ) {
                        if (j != i) {
                            int[] nsc2 = nsupporting[scores[j]];
                            if (nsc2[0] < 0) nsc2 = supporting[scores[j]];
                            if (nsc2[0] >= P || nsc2[1] >= P || nsc2[2] >= P)  res++;
                        }
                        for (int k = 0; k < N; k++) {
                            if (k != i && k != j) {
                                int[] sc = supporting[scores[k]];
                                if (sc[0] >= P || sc[1] >= P || sc[2] >= P)  res++;
                            }
                        }
                        ans = Math.max(res, ans);
                        res = 0;
                    }

                }
            }
            if (S == 3) {
                for (int i = 0; i < N; i++) {
                    int[] nsc = nsupporting[scores[i]];
                    if (nsc[0] < 0) nsc = supporting[scores[i]];
                    if (nsc[0] >= P || nsc[1] >= P || nsc[2] >= P)  res++;
                    for (int j = 0; j < N ; j++ ) {
                        if (j != i) {
                            int[] nsc2 = nsupporting[scores[j]];
                            if (nsc2[0] < 0) nsc2 = supporting[scores[j]];
                            if (nsc2[0] >= P || nsc2[1] >= P || nsc2[2] >= P)  res++;
                        }
                        for (int k = 0; k < N; k++) {
                            if (k != i && k != j) {
                                int[] nsc3 = nsupporting[scores[k]];
                                if (nsc3[0] < 0) nsc3 = supporting[scores[k]];
                                if (nsc3[0] >= P || nsc3[1] >= P || nsc3[2] >= P)  res++;
                            }
                            for (int l = 0; l < N; l++) {
                                if (l != i && l != j && l != k) {
                                    int[] sc = supporting[scores[l]];
                                    if (sc[0] >= P || sc[1] >= P || sc[2] >= P)  res++;
                                }
                            }
                            ans = Math.max(res, ans);
                            res = 0;
                        }

                    }

                }
            }
        }

        public void calculate (int supp, int a) {
            
            if (supp > S) return;
            if (supp == S) {
                ans = Math.max(ans, a);
                return;
            }
            for (int i = 0; i < N; i++) {
                selected[i] = true;
                int[] sc = supporting[scores[i]];
                boolean gr8 = false;
                if (sc[0] >= P || sc[1] >= P || sc[2] >= P) {
                    gr8 = true;
                }
                int[] nsc = nsupporting[scores[i]];
                if (nsc[0] < 0) nsc = sc;
                boolean nwgr8 = false;
                if (nsc[0] >= P || nsc[1] >= P || nsc[2] >= P)
                    nwgr8 = true;
                if (gr8) calculate(supp + 1, a);
                if (!gr8 && nwgr8) calculate(supp + 1, a + 1);
                selected[i] = false;
            }    
        }
        public void solveFast() {
            for (int i = 0; i < N; i++) {
                int[] sc = supporting[scores[i]];
                if (sc[0] >= P || sc[1] >= P || sc[2] >= P)  ans++;
            }
            calculate(0, ans);
        }

        public void printSelf(PrintWriter pw) {
            /*for (int sc : scores) {
                for (int j: s[sc])
                    pw.print(j + " ");
                pw.println();
                for (int j: ns[sc])
                    pw.print(j + " ");

            }             */
            pw.println(ans);
        }

        public boolean sameAnswers(Testcase other) {
            return false;
        }
    }

    final String AFTER_CASE = " ";
    
    int[][] supporting = new int[31][3];
    int[][] nsupporting = new int[31][3];

    int MAX_SCORE = 10;
    int NUM_JUDGES = 3;
    private void precalc() {
        for (int[] a: supporting)
            Arrays.fill(a, -1);
        for (int[] a: nsupporting)
            Arrays.fill(a, -1);
        for (int l = 0; l <= NUM_JUDGES * MAX_SCORE; l++) {
            for(int i = 0; i <= MAX_SCORE; i++) {
                for(int j = i; j < i + 3 && j <= MAX_SCORE; j++) {
                    for (int k = j;k < j + 3 && k < i + 3 && k <= MAX_SCORE; k++) {
                        if (i + j + k == l) {
                            if (Math.abs(i - j) <= 1 && Math.abs(i - k) <= 1 && Math.abs(j - k) <= 1) {
                                if (supporting[l][0] < 0) {
                                    supporting[l][0] = i;
                                    supporting[l][1] = j;
                                    supporting[l][2] = k;
                                }  else {
                                    int mE = Math.max(Math.max(supporting[l][0], supporting[l][1]),supporting[l][2]);
                                    int mC = Math.max(Math.max(i,j), k);
                                    if (mC > mE) {
                                        supporting[l][0] = i;
                                        supporting[l][1] = j;
                                        supporting[l][2] = k;
                                    }
                                    
                                }
                            } else {
                                if (nsupporting[l][0] < 0) {
                                    nsupporting[l][0] = i;
                                    nsupporting[l][1] = j;
                                    nsupporting[l][2] = k;
                                }  else {
                                    int mE = Math.max(Math.max(nsupporting[l][0], nsupporting[l][1]),nsupporting[l][2]);
                                    int mC = Math.max(Math.max(i,j), k);
                                    if (mC > mE) {
                                        nsupporting[l][0] = i;
                                        nsupporting[l][1] = j;
                                        nsupporting[l][2] = k;
                                    }

                                }
                            }
                        }    
                    }    
                }    
            }    
        }
    }
            
    public void go() throws Exception {

        precalc();
        Scanner sc = new Scanner(new FileReader("input.txt"));
        PrintWriter pw = new PrintWriter(new FileWriter("output.txt"));

        int caseCnt = sc.nextInt();
        
        for (int caseNum = 0; caseNum < caseCnt; caseNum++) {
            System.out.println("solving case " + caseNum);

            Testcase tc = new Testcase();

            tc.loadInput(sc, nsupporting, supporting);
            tc.solveSlow();

            pw.print("Case #" + (caseNum + 1) + ":");
            pw.print(AFTER_CASE);

            tc.printSelf(pw);
        }

        pw.flush();
        pw.close();
        sc.close();
    }

    public void stresstest() {
        int it = 0;
        Random rnd = new Random();
        while (true) {
            it++;
            if (it % 1000 == 0)
                System.out.println(it + " iterations");

            int seed = rnd.nextInt();

            Testcase tc1 = new Testcase(seed);
            tc1.solveFast();

            Testcase tc2 = new Testcase(seed);
            tc2.solveSlow();

            if (!tc1.sameAnswers(tc2)) {
                System.out.println("ERROR: it failed");
                System.exit(0);
            }
        }
    }

    public static void main(String[] args) throws Exception {
        new DancingWithGooglers().go();
    }
}

