#include using namespace std; #define int long long // <-----!!!!!!!!!!!!!!!!!!! #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--) #define all(a) (a).begin(),(a).end() typedef long long ll; typedef pair Pii; typedef tuple TUPLE; typedef vector V; typedef vector VV; typedef vector VVV; typedef vector> Graph; const int inf = 1e9; const int mod = 1e9 + 7; int m; vector a; map memo; int dfs(int r1, int r2, int i) { if (r1 < 0 || r2 < 0) return i - 1; if (i >= m) return i; if (memo[Pii(r1, r2)] != 0) return memo[Pii(r1, r2)]; return memo[Pii(r1, r2)] = max(dfs(r1 - a[i], r2, i + 1), dfs(r1, r2 - a[i], i + 1)); } signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int d; cin >> d; rep(_, d) { int n1, n2; cin >> n1 >> n2; cin >> m; a.resize(m); rep(i, m) cin >> a[i]; sort(all(a)); memo.clear(); cout << dfs(n1, n2, 0) << endl; } }