#include using namespace std; #define _p(...) (void)printf(__VA_ARGS__) #define forr(x,arr) for(auto&& x:arr) #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(int i=int(a);i=int(a);i--) #define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__) #define ALL(x) (x).begin(), (x).end() #define BIT(n) (1LL<<(n)) #define SZ(x) ((int)(x).size()) #define fst first #define snd second typedef vector vi;typedef vector vvi;typedef pair pii;typedef vector vpii; typedef long long ll; template inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } int dp[61][101]; void Main() { int N1, N2, M; scanf("%d%d%d", &N1, &N2, &M); vi A(M); rep(i, M) scanf("%d", &A[i]); sort(ALL(A)); memset(dp, 0xff, sizeof(dp)); dp[0][N1] = N2; rep(i, M) { bool ok = 0; rep(j, N1+1) if (dp[i][j] >= 0) { //_p("i:%d, a:%d, j:%d, k:%d\n", i,A[i],j,dp[i][j]); if (dp[i][j] >= A[i]) { dp[i+1][j] = dp[i][j] - A[i]; ok = 1; } if (j >= A[i]) { dp[i+1][j - A[i]] = dp[i][j]; ok = 1; } } if (!ok) { _p("%d\n", i); return; } } _p("%d\n", M); } int main() { int T; scanf("%d", &T); while (T--) Main(); return 0; }