#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair P; #define MOD 1000000007 // 10^9 + 7 #define INF 1000000000 // 10^9 #define LLINF 1LL<<60 int dp[69][100009]; // dp[i][j] : 小さい順に竹をi個使い、そのうち長さjをm1から取るときの最大個数 int main() { cin.tie(0); ios::sync_with_stdio(false); int d; cin >> d; vector ans; for (int q = 0; q < d; q++) { int n1, n2, m; cin >> n1 >> n2 >> m; int A[100]; for (int i = 0; i < m; i++) cin >> A[i]; sort(A, A + m); int sum[100]; sum[0] = A[0]; for (int i = 1; i < m; i++) sum[i] = sum[i - 1] + A[i]; for (int i = 0; i < 65; i++) { for (int j = 0; j <= n1; j++) dp[i][j] = -1; } int res = 0; if (n1 >= A[0]) dp[0][A[0]] = 1; if (n2 >= A[0]) dp[0][0] = 1; for (int i = 0; i < m-1; i++) { for (int j = 0; j <= n1; j++) { if (dp[i][j] != -1) { if (n1 - j - A[i + 1] >= 0) { dp[i + 1][j + A[i + 1]] = max(dp[i + 1][j + A[i + 1]], dp[i][j] + 1); res = max(res, dp[i + 1][j + A[i + 1]]); } if (n2 - (sum[i] - j) - A[i + 1] >= 0) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + 1); res = max(res, dp[i + 1][j]); } } } } ans.push_back(res); } for (int k = 0; k < d; k++)cout << ans[k] << endl; return 0; }