package code12.qualification;

import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;

public class B {
	public static String solve(int N, int S, int p, int[] t) {
		
		// 3a 		-> (a, a, a), *(a - 1, a, a + 1)
		// 3a + 1	-> (a, a, a + 1), *(a - 1, a + 1, a + 1)
		// 3a + 2	-> (a, a + 1, a + 1), *(a, a, a + 2)
		
		int numPNoS = 0;
		int numPWithS = 0;
		
		for (int i = 0; i < N; i++) {
			int a = (int)Math.floor(t[i] / 3);
			int r = t[i] % 3;
			
			switch (r) {
			case 0:
				if (a >= p) {
					numPNoS++;
				} else if (a + 1 >= p && a - 1 >= 0) {
					numPWithS++;
				}
				break;
			case 1:
				if (a >= p || a + 1 >= p) {
					numPNoS++;
				}
				break;
			case 2:
				if (a >= p || a + 1 >= p) {
					numPNoS++;
				} else if (a + 2 >= p) {
					numPWithS++;
				}
				break;
			}
		}
		
		return "" + (numPNoS + Math.min(S, numPWithS));
	}

	public static void main(String[] args) throws Exception {
		// file name
		//String fileName = "Sample";
		//String fileName = "B-small";
		String fileName = "B-large";
		
		// file variable
		File inputFile = new File(fileName + ".in");
		File outputFile = new File(fileName + ".out");
		Scanner scanner = new Scanner(inputFile);
		FileWriter writer = new FileWriter(outputFile);

		// problem variable
		int totalCase;
		int N, S, p;
		int[] t;

		// get total case
		totalCase = scanner.nextInt();

		for (int caseIndex = 1; caseIndex <= totalCase; caseIndex++) {
			// get input
			N = scanner.nextInt();
			S = scanner.nextInt();
			p = scanner.nextInt();
			t = new int[N];
			
			for (int i = 0; i < N; i++) {
				t[i] = scanner.nextInt();
			}
			
			String output = "Case #" + caseIndex + ": " + solve(N, S, p, t);
			System.out.println(output);
			writer.write(output + "\n");
		}
		scanner.close();
		writer.close();
	}
}

package Triple;

public class Triple
{
	private int X;
	private int Y;
	private int Z;

	public Triple()
	{
		this.X = 0;
		this.Y = 0;
		this.Z = 0;
	}

	public Triple(int x, int y, int z)
	{
		this.X = x;
		this.Y = y;
		this.Z = z;
	}

	public Triple(int total)
	{
		this.X = total / 3;
		this.Y = (total - this.X) / 2;
		this.Z = (total - this.X - this.Y);
	}

	public Boolean isValid()
	{
		if (Math.abs(this.X - this.Y) > 2)
		{
			return false;
		}
		if (Math.abs(this.X - this.Z) > 2)
		{
			return false;
		}
		if (Math.abs(this.Y - this.Z) > 2)
		{
			return false;
		}

		return true;
	}

	// A result of "True" indicates that a Triple is valid but unusual. "False"
	// could indicate invalid, or valid but not unusual (it's up to you to
	// discriminate)
	public Boolean isUnusual()
	{
		if (!this.isValid())
		{
			return false;
		}
		if (Math.abs(this.X - this.Y) > 1)
		{
			return true;
		}
		if (Math.abs(this.X - this.Z) > 1)
		{
			return true;
		}
		if (Math.abs(this.Y - this.Z) > 1)
		{
			return true;
		}

		return false;
	}

	public Boolean isHigher(int p)
	{
		Boolean high = false;
		if (this.X >= p)
		{
			high = true;
		}
		if (this.Y >= p)
		{
			high = true;
		}
		if (this.Z >= p)
		{
			high = true;
		}

		return high;
	}

	// A false response indicates either the Triple is already higher, or can't
	// be made higher without invalidating
	public Boolean couldBeHigher(int p)
	{
		Boolean high = false;
		if (this.isHigher(p))
		{
			return false;
		}
		
		if ((this.X == p - 1) && (this.X > 0))
		{
			high = true;
		}
		if ((this.Y == p - 1) && (this.Y > 0))
		{
			high = true;
		}
		if ((this.Z == p - 1) && (this.Z > 0))
		{
			high = true;
		}

		return high;
	}

	public void Unusify()
	{
		int highest = Math.max(this.X, Math.max(this.Y, this.Z));
		int lowest = Math.min(this.X, Math.min(this.Y, this.Z));
		if (this.X == highest)
		{
			this.X += 1;
			if (this.Y == lowest)
			{
				this.Z -= 1;
			} else
			{
				this.Y -= 1;
			}
		} else if (this.Y == highest)
		{
			this.Y += 1;
			if (this.X == lowest)
			{
				this.Z -= 1;
			} else
			{
				this.X -= 1;
			}
		} else
		// this.Z == highest
		{
			this.Z += 1;
			if (this.Y == lowest)
			{
				this.X -= 1;
			} else
			{
				this.Y -= 1;
			}
		}
	}

	@Override
	public String toString()
	{
		return "(" + this.X + ", " + this.Y + ", " + this.Z + ")" + (this.isUnusual() ? " is unusual" : "") + (this.isValid() ? "" : " is invalid");
	}

}
