#include <iostream>
#include <vector>
#include <algorithm>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
using namespace std;
int main() {
    int dataset; cin >> dataset;
    while (dataset --) {
        // input
        int n1, n2, m; cin >> n1 >> n2 >> m;
        vector<int> as(m); repeat (i,m) cin >> as[i];
        // roughly estimate
        whole(sort, as);
        int acc = 0;
        int cnt = 0;
        for (int a : as) {
            if (n1 + n2 < acc + a) break;
            acc += a;
            ++ cnt;
        }
        // check the boundary
        vector<bool> dp(n1+1);
        dp[0] = true;
        for (int a : as) {
            repeat_reverse (i, n1) if (dp[i]) {
                if (i + a < n1+1) {
                    dp[i + a] = true;
                }
            }
        }
        int last = n1;
        while (not dp[last]) -- last;
        bool found = (acc - last <= n2);
        // output
        cout << (cnt - not found) << endl;
    }
    return 0;
}