import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) def test(): x, y = map(int, input().split()) m = int(input()) A = sorted(map(int, input().split())) dp = {(0, 0), } ans = 0 for i, a in enumerate(A, 1): newDP = set() for (lx, ly) in dp: if lx + a <= x: newDP.add((lx + a, ly)) if ly + a <= y: newDP.add((lx, ly + a)) dp = newDP if dp: ans = i return ans d = int(input()) print(*[test() for _ in range(d)], sep="\n")