#pragma GCC optimize ("O3") #pragma GCC target ("avx") #include "bits/stdc++.h" // define macro "/D__MAI" using namespace std; typedef long long int ll; #define debugv(v) {printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout< ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout< ostream& operator <<(ostream &o, const pair p) { o << "(" << p.first << ":" << p.second << ")"; return o; } mt19937 mt(8901016); inline int rand_int(int l, int h) { return uniform_int_distribution<>(l, h)(mt); } #ifdef __MAI #define getchar_unlocked getchar #define putchar_unlocked putchar #endif #ifdef __VSCC #define getchar_unlocked _getchar_nolock #define putchar_unlocked _putchar_nolock #endif namespace { #define isvisiablechar(c) (0x21<=(c)&&(c)<=0x7E) class MaiScanner { public: template void input_integer(T& var) { var = 0; T sign = 1; int cc = getchar_unlocked(); for (; cc<'0' || '9'>(int& var) { input_integer(var); return *this; } inline MaiScanner& operator>>(long long& var) { input_integer(var); return *this; } inline MaiScanner& operator>>(string& var) { int cc = getchar_unlocked(); for (; !isvisiablechar(cc); cc = getchar_unlocked()); for (; isvisiablechar(cc); cc = getchar_unlocked()) var.push_back(cc); } template void in(IT begin, IT end) { for (auto it = begin; it != end; ++it) *this >> *it; } }; } MaiScanner scanner; void solve() { int l1, l2; int m; scanner >> l1 >> l2 >> m; if (l1 < l2) swap(l1, l2); int best = 1; vector aa(m); scanner.in(ALL(aa)); sort(ALL(aa)); vector imos(m + 1); for (int i = 0; i < m; ++i) imos[i + 1] = imos[i] + aa[i]; map dp1; dp1[0] = 1; for (int i = 0; i < aa.size(); ++i) { int a = aa[i]; map dp2; for (int l = 0; l <= l1; ++l) { if (dp1[l] == 0) continue; int l2_used = (imos[i] - l); // L1を使う if (l + a <= l1) best = max(best, dp2[l + a] = dp1[l] + 1); // L2を使う if (l2_used + a <= l2) best = max(best, dp2[l] = dp1[l] + 1); } //debugv(dp2); dp1.swap(dp2); } cout << (best-1) << endl; } int main() { int qcnt; scanner >> qcnt; repeat(qcnt) { solve(); } return 0; }