MAX = 100000 def accept(n1, n2, fragments, upper): if upper == 0: return True total = 0 for i in range(upper): total = total + fragments[i] if n1+n2 < total: return False dp = [False for _ in range(MAX)] dp[0] = True for i in range(upper): for j in reversed(range(MAX)): if dp[j]: if j + fragments[i] <= n1: dp[j + fragments[i]] = True for i in reversed(range(MAX)): if dp[i] and total - i <= n2: return True return False N = int(input()) for i in range(N): n1, n2 = sorted(list(map(int, input().split(' ')))) m = int(input()) fragments = sorted(list(map(int, input().split(' ')))) for j in reversed(range(0,m+1)): if accept(n1, n2, fragments, j): print(j) break