#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; namespace std { template <> class hash> { public: size_t operator()(const std::pair& x) const{ return hash()(x.first) ^ hash()(x.second); } }; } int solve(int n1, int n2, const vector& v){ unordered_map< pair, int> dp[65]; dp[0][make_pair(0,0)] = 0; rep(i,v.size()){ FOR(it,dp[i]){ pair p = it->first; int x = it->second; dp[i+1][p] = max(dp[i+1][p], x); if(p.first+v[i]<=n1) dp[i+1][make_pair(p.first+v[i],p.second)] = max(dp[i+1][make_pair(p.first+v[i],p.second)], x + 1); if(p.second+v[i]<=n2) dp[i+1][make_pair(p.first,p.second+v[i])] = max(dp[i+1][make_pair(p.first,p.second+v[i])], x + 1); } } int ret = 0; FOR(it,dp[v.size()]){ ret = max(ret, it->second); } return ret; } int main(){ ios::sync_with_stdio(false); int d; cin >> d; rep(i,d){ int n1, n2; int m; cin >> n1 >> n2; cin >> m; vector A; rep(j,m){ int a; cin >> a; A.push_back(a); } cout << solve(n1, n2, A) << endl; } return 0; }