#ifndef LOCAL #include using namespace std; #define debug(...) (void(0)) #else #include "algo/debug.h" #endif void solve() { int N1, N2; cin >> N1 >> N2; int M; cin >> M; vector A(M); for(int i = 0; i < M; i++) cin >> A[i]; sort(A.begin(), A.end()); vector> dp(M + 1, vector(N1 + 1)); dp[0][0] = 1; int sum = 0; int ans = 0; for(int i = 0; i < M; i++) { bool f = false; for(int j = 0; j <= N1; j++) { if(dp[i][j]) { if(j + A[i] <= N1) { dp[i + 1][j + A[i]] = 1; f = true; } if(sum - j + A[i] <= N2) { dp[i + 1][j] = 1; f = true; } } } sum += A[i]; if(f) ans++; else break; } cout << ans << endl; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int tt = 1; std::cin >> tt; while(tt--) { solve(); } }