d = int(input()) for _ in range(d): n1, n2 = map(int, input().split()) input() A = sorted(map(int, input().split())) ans = 0 syugo = {(n1, n2)} for a in A: if syugo == set(): break new_syugo = set() for x, y in syugo: if x - a >= 0: new_syugo.add((x - a, y)) if y - a >= 0: new_syugo.add((x, y - a)) syugo = new_syugo ans += 1 print(ans - 1)