//#include #include using namespace std; typedef long long ll; typedef pair p; const int INF = 1e9; const ll LINF = ll(1e18); const int MOD = 1000000007; const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define rep(i, n) for (int i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) \ { \ cout << x << ' '; \ } \ cout << endl; template bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //cout<> d; vector ans(d); rep(k, d) { int d1, d2; cin >> d1 >> d2; int n; cin >> n; vector a(n); rep(j, n) { cin >> a[j]; } sort(ALL(a)); vector> dp(n + 1, vector(d1 + 1, -1)); dp[0][0] = 0; int sum = 0; int anst = 0; rep(i, n) { rep(j, d1 + 1) { if (dp[i][j] >= 0) { chmax(anst, dp[i][j]); int j2 = sum - j; //現在のd2の使用 if (j + a[i] <= d1) dp[i + 1][j + a[i]] = max(dp[i][j] + 1, dp[i + 1][j + a[i]]); //n1に入るならいれる if (j2 + a[i] <= d2) dp[i + 1][j] = max(dp[i][j] + 1, dp[i + 1][j]); } } sum += a[i]; } rep(i,d1+1)chmax(anst,dp[n][i]); ans[k] = anst; } rep(i, d) cout << ans[i] << "\n"; }