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

public class DancingWithTheGooglers
{
    public DancingWithTheGooglers()
    {
        Scanner inFile = null;
        try
        {
            inFile = new Scanner(new File("inputB.txt"));
        }
        catch(Exception e)
        {
            System.out.println("Problem opening input file. Exiting...");
			System.exit(0);
        }
        int t = inFile.nextInt();
        
        int [] results = new int [t];
        DancingWithTheGooglersMax [] rnc = new DancingWithTheGooglersMax[t];
        
        int i, j;
        int [] scores;
        int s, p;
        for(i = 0; i < t; i++)
        {
            scores = new int [inFile.nextInt()];
            s = inFile.nextInt();
            p = inFile.nextInt();
            for(j = 0; j < scores.length; j++)
                scores[j] = inFile.nextInt();
            
            rnc[i] = new DancingWithTheGooglersMax(i, scores, s, p, results);
            rnc[i].start();
        }
        inFile.close();
        
        boolean done = false;
        
        while(!done)
        {
            done = true;
            for(i = 0; i < t; i++)
                if(rnc[i].isAlive())
                {
                    done = false;
                    break;
                }
        }
        
        PrintWriter outFile = null;
        try
        {
            outFile = new PrintWriter(new File("outputB.txt"));
        }
        catch(Exception e)
        {
            System.out.println("Problem opening output file. Exiting...");
			System.exit(0);
        }
        
        for(i = 0; i < results.length; i++)
            outFile.printf("Case #%d: %d\n", i+1, results[i]);
        outFile.close();
    }
    
    public static void main(String [] args)
    {
        new DancingWithTheGooglers();
    }
    
    private class DancingWithTheGooglersMax extends Thread
    {
        int id;
        int s, p;
        int [] results, scores;
        
        public DancingWithTheGooglersMax(int i, int [] aScores, int aS, int aP,int [] res)
        {
            id = i;
            s = aS;
            p = aP;
            results = res;
            scores = aScores;
        }
        
        public void run()
        {
            int a = 0, b = 0;
            
            if(p == 0)
                results[id] = scores.length;
            else if(p == 1)
            {
                int y;
                y = 3*p - 3;
                
                for(int i = 0; i < scores.length; i++)
                    if(scores[i] > y)
                        a++;
                    else if(scores[i] > 0)
                        b++;
                
                b = Math.min(b, s);
                results[id] = a+b;
            }
            else
            {
                int y, z;
                y = 3*p - 3;
                z = 3*p - 5;
                
                for(int i = 0; i < scores.length; i++)
                    if(scores[i] > y)
                        a++;
                    else if(scores[i] > z)
                        b++;
                
                b = Math.min(b, s);
                results[id] = a+b;
            }
        }
    }
}
import java.io.BufferedReader;
import java.io.FileReader;


public class DancingTest {

	public static void main(String[] args) {
		int numCase = 0;
		int caseIndex = 0;
		int[] numGooglers = null;
		int[] numSurprises = null;
		int[] bestResult = null;
		int[][] scores = null;
		int maxNumScores = 100;
		
		try {
			FileReader reader = new FileReader("C:\\Users\\CheeMeng\\Downloads\\B-large.in");
			BufferedReader br = new BufferedReader(reader);
			String s = br.readLine();
			numCase = new Integer(s).intValue();
			numGooglers = new int[numCase];
			numSurprises = new int[numCase];
			bestResult = new int[numCase];
			scores = new int[numCase][maxNumScores];
			while((s = br.readLine()) != null) {
				String s1[] = s.split(" ");
				numGooglers[caseIndex] = new Integer(s1[0]).intValue();
				numSurprises[caseIndex] = new Integer(s1[1]).intValue();
				bestResult[caseIndex] = new Integer(s1[2]).intValue();
				for (int i = 3; i < s1.length; i++)  {
					scores[caseIndex][i - 3] = new Integer(s1[i]).intValue();
				}
				caseIndex++;
			} 
			reader.close(); 
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		for (int i = 1; i <= numCase; i++)  {
			System.out.println("Case #" + i + ": " + dancingTest(numGooglers[i - 1], numSurprises[i - 1], bestResult[i - 1], scores[i - 1]));
		}
	}
	
	public static int dancingTest(int numGooglers, int numSurprises, int bestResult, int[] scores)  {
		int count = 0;
		int nearMisses = 0;
		for (int i = 0; i < numGooglers; i++)  {
			int best = 0;
			if ((scores[i] % 3) == 0)  {
				// Assume scores are (x, x, x), so best score will be the average
				best = scores[i] / 3;
				// Specially consider the case where scores are (x - 1, x, x + 1)
				if ((best == bestResult - 1) && (best >= 1) && (best <= 9)) {
					nearMisses++;
				}
			}
			else if ((scores[i] % 3) == 2)  {
				// Assume scores are (x - 1, x, x), so best score will be the average
				best = (scores[i] + 1) / 3;
				// Specially consider the case where scores are (x - 1, x - 1, x + 1)
				if ((best == bestResult - 1) && (best >= 1) && (best <= 9)) {
					nearMisses++;
				}
			}
			else if ((scores[i] % 3) == 1)  {
				// Scores will be either (x - 1, x - 1, x) or (x - 2, x, x)
				// doesn't matter if any of them is marked surprising
				best = (scores[i] + 2) / 3;
			}
			if (best >= bestResult)  {
				count++;
			}
		}
		
		count = count + Math.min(nearMisses, numSurprises);
		return count;
	}
}
