d = input() def rec(p, m, A, L): if p > m-1: return True if A[p] <= L[0]: L[0] -= A[p] if rec(p+1, m, A, L): return True L[0] += A[p] if A[p] <= L[1]: L[1] -= A[p] if rec(p+1, m, A, L): return True L[1] += A[p] return False def solve(A, L): for i in xrange(len(A), -1, -1): if rec(0, i, A, L): print i break for i in xrange(d): L = map(int, raw_input().split()) input() A = sorted(map(int, raw_input().split())) solve(A, L)