import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Iterator; public class Main { public static Scanner sc=new Scanner(System.in); public static Printer pr=new Printer(System.out); public static void main(String[] args) { int d = sc.nextInt(); for(;d>0;d--){ new Main().solver(); } pr.close(); } void solver() { int n1 = sc.nextInt(); int n2 = sc.nextInt(); int m = sc.nextInt(); int[] a = new int[m]; for (int i = 0; i < m; i++) { a[i] = sc.nextInt(); } Arrays.sort(a); boolean[] from = new boolean[n1 + 1]; from[0] = true; int len = 0; for (int i = 0; i < m; i++) { boolean[] to = new boolean[100001]; boolean f=false; for (int j = 0; j <= n1; j++) { if (from[j]) { if (j + a[i] <= n1) { to[j + a[i]] = true; f=true; } if ((len - j) + a[i] <= n2) { to[j] = true; f=true; } } } len+=a[i]; from=to; if(!f){ pr.println(i); return; } } pr.println(m); } void tr(Object...o){System.out.println(Arrays.deepToString(o));} private static class Scanner{ BufferedReader br; Iterator it; Scanner(InputStream in){ br=new BufferedReader(new InputStreamReader(in)); } String next()throws RuntimeException{ try{ if(it==null||!it.hasNext()) it=Arrays.asList(br.readLine().split(" ")).iterator(); return it.next(); }catch(IOException e){ throw new IllegalStateException(); } } int nextInt() throws RuntimeException{ return Integer.parseInt(next()); } long nextLong() throws RuntimeException{ return Long.parseLong(next()); } double nextDouble() throws RuntimeException{ return Double.parseDouble(next()); } void close(){ try{ br.close(); }catch(IOException e){ throw new IllegalStateException(); } } } private static class Printer extends PrintWriter{ Printer(PrintStream out){ super(out); } } }