from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    def ok(c,i=0,s=0):
        if cs[c]>n1+n2:return False
        if s>n1:return False
        if cs[c]-n2<=s:return True
        if i==c:return False
        if ok(c,i+1,s) or ok(c,i+1,s+aa[i]):return True

    for _ in range(II()):
        n1,n2=MI()
        m=II()
        aa=LI()
        if n1>n2:n1,n2=n2,n1
        aa.sort()
        cs=[0]
        for a in aa:cs.append(cs[-1]+a)
        l=-1
        r=m+1
        while l+1<r:
            c=(l+r)//2
            if ok(c):l=c
            else:r=c
        print(l)

main()