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


}

package qualification;

import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.Vector;

public class ProblemB {
	
	static Scanner scan = new Scanner(System.in);
	
	public static void main(String[] args) {

		

		int cases = scan.nextInt();
		
		for ( int i = 1; i <= cases; i++ ) {
			
			System.out.println("Case #" + i + ": " + solveCase());
			
			
		}

	}
	
	public static int solveCase() {
		int numGooglers = scan.nextInt();
		int numSurprising = scan.nextInt();
		int p = scan.nextInt();
		
		Vector<Triplet> containsGreaterThanP = new Vector<Triplet>();
		Vector<Triplet> containsPminus1 = new Vector<Triplet>();
		
		for ( int j = 0; j < numGooglers; j++ ) {
			Triplet t = new Triplet();
			
			int score = scan.nextInt();
			int n = Math.round( score / 3f );
			int n_2 = score - 2*n;
			
			// Ordered triplets
			if ( n_2 > n ) {
				t.add(n_2);
				t.add(n);
				t.add(n);
			} else {
				t.add(n);
				t.add(n);
				t.add(n_2);
			}
			
			if ( t.containsGreaterThan(p) ) {
				// Check if it can be made surprising
				containsGreaterThanP.add(t);
			} else if ( t.contains(p-1) > 1 && p > 1 && t.contains(0) <= 1) {
				containsPminus1.add(t);
			}
		}
//				System.out.println("Googlers: " + numGooglers);
//		System.out.println("Surprising: " + numSurprising);
//		System.out.println("P: " + p);
//		System.out.println(containsGreaterThanP);
//		System.out.println(containsPminus1);
		
		return containsGreaterThanP.size() + Math.min(numSurprising, containsPminus1.size());
		

	}
	
	static class Triplet {
		int[] values = new int[3];
		
		int i = 0;
		
		public void add(int a) {
			if ( i > 2)
				throw new InputMismatchException("Bad input");
			
			values[i] = a;
			i++;
		}
		
		public int contains(int v) {
			
			int retval = 0;
			
			retval += values[0] == v ? 1 : 0;
			retval += values[1] == v ? 1 : 0;
			retval += values[2] == v ? 1 : 0;
			
			return retval;

		}
		
		public boolean containsGreaterThan(int v) {
			// Ordered triplets
			return values[0] >= v;
		}
		
		public boolean allEqual() {
			return values[0] == values[1] && values[1] == values[2];
		}
		
		public String toString() {
			return "(" + values[0] + " " + values[1] + " " + values[2] + ")";
		}
	}
}
