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.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;



public class test1 {
	ArrayList<String > result=new ArrayList<String>();
	
	Hashtable<Character, Character> h=new Hashtable<Character, Character>();
	int count =0;
	
	public void read_file() throws Exception {
		FileReader g = new FileReader("B-large.in");
		BufferedReader br = new BufferedReader(g);
		int No_of_Cases = Integer.parseInt(br.readLine());
		String s;
		for(int i=0;i<No_of_Cases;i++)
		{
			s=br.readLine();									// ha2ra el lines hena 
			solve2(s);
		}
		g.close();
		write_file();
	}
	
	public void solve2(String s)
	{
		String [] g=s.split(" ");
		int googleres=Integer.parseInt(g[0]);
		int sur=Integer.parseInt(g[1]);
		int target=Integer.parseInt(g[2]);
		if(target==0)
		{
			result.add(g.length-3+"");
			return;
		}
		int min_target=target*3-4;;
		int max_target=target*3-2;
		int counta=0;
		int countb=0;
		int temp;
		for(int i=3;i<g.length;i++)
		{
			temp=Integer.parseInt(g[i]);
			if (temp!=0 || target!=1)
			{
				if(temp>=min_target)
				{
					if(temp >=max_target)
					{
						counta++;
					}else
					{
						countb++;
					}
				}
			}
		}
		if(countb<sur)
		{
			counta+=countb;
		}else
		{
			counta+=sur;
		}
		result.add(counta+"");
		
	}
	
	
	
	public void Equal(String s1,String s2)
	{
		for (int i=0;i<s1.length();i++)
		{
			if(h.get(s1.charAt(i))==null)
			{
				h.put(s1.charAt(i), s2.charAt(i));
			}
		}
	}
	
	public void Main1() throws Exception
	{
		tet1();
		read_file();
		write_file();
	}
	
	public String op1(String s)
	{
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<s.length();i++)
		{
			sb.append(h.get(s.charAt(i)));
		}
		return sb.toString();
	}
	
	public void tet1()
	{
		String [] s={"ejp mysljylc kd kxveddknmc re jsicpdrysi","rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd","de kr kd eoya kw aej tysr re ujdr lkgc jv"};
		String [] s1={"our language is impossible to understand","there are twenty six factorial possibilities","so it is okay if you want to just give up"};
		for (int i=0;i<3;i++)
		{
			Equal(s[i], s1[i]);
		}
		h.put('z', 'q');
		h.put('q', 'z');
		System.out.println(h.size());
	}
	
	public void write_file() throws IOException
	{
		BufferedWriter br=new BufferedWriter(new FileWriter("test1.txt"));
		for(int i=0;i<result.size();i++)
		{
			br.write("Case #"+(i+1)+": "+result.get(i));
			if(i!=result.size()-1)
			{
				br.newLine();
			}
		}
		br.close();
	}
	
	public static void main (String [] args) throws Exception
	{
		test1 t=new test1();
//		t.read_file();
//		t.write_file();
		t.read_file();
	}
	
}
