d = int(input()) for _ in range(d): n1, n2 = map(int, input().split()) m = int(input()) A = list(map(int, input().split())) A.sort() dp = [[False]*(n1+1) for _ in range(m+1)] dp[0][0] = True acc = 0 for i in range(m): for j in range(n1+1): if j+A[i]<=n1: dp[i+1][j+A[i]] |= dp[i][j] n2_used = acc-j if n2_used+A[i]<=n2: dp[i+1][j] |= dp[i][j] acc += A[i] for i in range(m, -1, -1): for j in range(n1+1): if dp[i][j]: print(i) break else: continue break