#include #include #include using namespace std; int N0, N1; int M; int A[60]; bitset<100001> dp; int main() { int numCases; scanf("%d", &numCases); for (; numCases--; ) { scanf("%d%d%d", &N0, &N1, &M); for (int i = 0; i < M; ++i) { scanf("%d", &A[i]); } sort(A, A + M); dp.reset(); dp.set(0); int sum = 0; int ans = 0; for (int i = 0; i < M; ++i) { dp |= dp << A[i]; sum += A[i]; for (int x = max(sum - N1, 0); x <= N0; ++x) { if (dp[x]) { ans = i + 1; break; } } } printf("%d\n", ans); } return 0; }