#include #include #include #include //#include #include #include #include #include #include //#include #include #include #include //#include #include //#include #include #include #include #include #include const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, -1, 0, 1}; using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector vi; typedef vector vll; typedef pair pii; const int MAX = 100010; bool dp[66][MAX]; 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()); memset(dp, false, sizeof(dp)); dp[0][0] = true;; int sum = 0; for (int i = 0; i < M; i++) { sum += A[i]; for (int j = MAX-1; j >= 0; j--) if (dp[i][j]) { if (sum-j <= N2) dp[i+1][j] = true; if (j+A[i] <= N1) dp[i+1][j+A[i]] = true; } } for (int i = M; i >= 0; i--) { if (find(dp[i], dp[i]+MAX, true) != end(dp[i])) { cout << i << endl; return; } } } int main() { cin.tie(0); ios::sync_with_stdio(false); int T; cin >> T; while (T--) { solve(); } return 0; }