#include #include #include #include #include using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) int dp[61][100001]; int main(void){ int d; cin >> d; while(d){ int n1, n2; cin >> n1 >> n2; int sum = n1 + n2; int max_n = max(n1, n2); int m; cin >> m; vector a(m + 1); a[0] = 0; rep(i, m) cin >> a[i + 1]; sort(a.begin(), a.end()); vector s(m + 1); s[0] = 0; rep(i, m) s[i + 1] += s[i] + a[i + 1]; //rep(i, m + 1) printf("%d %d\n", a[i], s[i]); //初期化 rep(i, 61)rep(j, 100001) dp[i][j] = -1; dp[0][n1] = 0; for (int i = 0; i < m; ++i){ for (int j = 0; j <= n1 ; ++j){ //n1から切り出す if(j - a[i + 1] >= 0 && dp[i][j] != -1){ dp[i + 1][j - a[i + 1]] = dp[i][j] + 1; //printf("dp[%d][%d] = %d\n", i + 1, j - a[i + 1], dp[i + 1][j - a[i + 1]]); } //n2から切り出す if(sum - j - s[i] >= a[i + 1] && dp[i][j] != -1){ dp[i + 1][j] = dp[i][j] + 1; //printf("dp[%d][%d] = %d\n", i + 1, j, dp[i + 1][j]); } } } int ans = -2; rep(i, 61) rep(j, 100001) ans = max(ans, dp[i][j]); printf("%d\n", ans); d--; } }