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

public class DancingWithGooglers {

  public static class Googlers {

    public int T;
    public int surp;
    public boolean surprising;
    public boolean pSurprising;
    public boolean antiSurprising;
    public boolean pAntiSurprising;

    public Googlers(int T, int surp) {
      this.T = T;
      this.surp = surp;
    }

    public void set(int a, int b, int c) {
      if (c >= 0 && (a + b + c) == T) {
        int diff = (Math.max(a, Math.max(b, c)) - Math.min(a, Math.min(b, c)));
        if (diff <= 2) {
          if (diff == 2) {
            if (a >= surp || b >= surp || c >= surp) {
              pSurprising = true;
            } else {
              surprising = true;
            }
          } else {
            if (a >= surp || b >= surp || c >= surp) {
              pAntiSurprising = true;
            } else {
              antiSurprising = true;
            }
          }
        }
      }
    }
  }

  public static void main(String... args) throws IOException {
//    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    BufferedReader reader = new BufferedReader(new FileReader("B-large.in"));
//    PrintWriter writer = new PrintWriter(System.out);
    PrintWriter writer = new PrintWriter("B-large.out");

    int len, cases = Integer.parseInt(reader.readLine());
    List<Googlers> satisfied = new ArrayList<Googlers>();
    List<Googlers> unsatisfied = new ArrayList<Googlers>();
    String[] inputs;
    int N, S, p;
    for (int i = 1; i <= cases; i++) {
      inputs = reader.readLine().split(" ");
      p = Integer.parseInt(inputs[1]);
      S = Integer.parseInt(inputs[2]);
      satisfied.clear();
      unsatisfied.clear();
      for (int j = 3; j < inputs.length; j++) {
        int t = Integer.parseInt(inputs[j]);
        Googlers googlers = new Googlers(t, S);

        for (int k = 0; k <= 10; k++) {
          int till = k + 2 > 10 ? 10 : k + 2;
          for (int l = k; l <= till; l++) {
            googlers.set(k, l, (t - (k + l)));
          }
        }
        if (googlers.pAntiSurprising) {
          satisfied.add(googlers);
        } else {
          unsatisfied.add(googlers);
        }
      }
      int pSurprising = 0;
      if (p > 0) {
        for (Iterator<Googlers> iter = unsatisfied.iterator(); iter.hasNext(); ) {
          Googlers googlers = iter.next();
          if (googlers.pSurprising) {
            pSurprising++;
            iter.remove();
            p--;
            if (p <= 0) break;
          }
        }
      }
      if(p > 0){
        for (Iterator<Googlers> iter = unsatisfied.iterator(); iter.hasNext(); ) {
          Googlers googlers = iter.next();
          if (googlers.surprising) {
            iter.remove();
            p--;
            if (p <= 0) break;
          }
        }
      }
      if(p > 0){
        for (Iterator<Googlers> iter = satisfied.iterator(); iter.hasNext(); ) {
          Googlers googlers = iter.next();
          if (googlers.pSurprising) {
            iter.remove();
            pSurprising++;
            p--;
            if (p <= 0) break;
          }
        }
      }
      if(p > 0){
        for (Iterator<Googlers> iter = satisfied.iterator(); iter.hasNext(); ) {
          Googlers googlers = iter.next();
          if (googlers.surprising) {
            iter.remove();
            p--;
            if (p <= 0) break;
          }
        }
      }

      if(p > 0){
        writer.print("Case #" + i + ": 0");
      }else {
        writer.print("Case #" + i + ": " + (satisfied.size() + pSurprising));
      }
      writer.println();
    }
    writer.flush();
  }


}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package google;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Arber
 */
public class Google {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Path input_path = new File("Input.in").toPath();
        try {
            List<String> input_list = Files.readAllLines(input_path,Charset.forName("UTF-8"));
            int begin = 0;
            while(begin<input_list.size())
            {
                int start = new Integer(input_list.get(begin)).intValue();
                for(int i = 0; i<start; i++)
                {
                    String[] in = input_list.get(begin+i+1).split(" ");
                    int[] t = new int[in.length-3];
                    for(int j=3; j<in.length;j++)
                    {
                        t[j-3] = new Integer(in[j]).intValue();
                    }
                    System.out.println("Case #"+(i+1)+": " +google4(new Integer(in[0]).intValue(), new Integer(in[1]).intValue(), new Integer(in[2]).intValue(), t));
                }
                begin = begin + start + 1;
            }
        } catch (IOException ex) {
            Logger.getLogger(Google.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static int google3(int n, int m)
    {
        ArrayList<String> a1 = new ArrayList<String>();
        for(int i = n; i<=m; i++)
        {
            for(int j = 1; j<(""+n).length();j++)
            {
                int rec = recycled(""+i, j);
                if(rec>=n &&rec<=m && rec != i)
                {
                    if(rec<i)
                    {
                        String tem = (""+rec)+(""+i);
                        if(!a1.contains(tem))
                            a1.add(tem);
                    }
                    else
                    {
                        String tem = (""+i)+(""+rec);
                        if(!a1.contains(tem))
                            a1.add(tem);
                    }
                }
            }
        }
        return a1.size();
            
    }
    public static int recycled(String s, int m)
    {
        s = s.substring(s.length()-m) + s.substring(0,s.length()-m);
        return new Integer(s).intValue();
    }
    public static int google4(int T,int s,int p, int[] t)
    {
        int rez = 0;
        for(int i=0; i<T; i++)
        {
            if(t[i]>=3*p-2)
                rez++;
            else if((t[i]>=3*p-4&&s>0&&p>1))
            {
                s--;
                rez++;
            }
        }
        return rez;
    }
}
