#include #include #include #include #include using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) int main(void){ int d; cin >> d; while(d > 0){ int n1, n2; cin >> n1 >> n2; int m; cin >> m; vector a(m); rep(i, m) cin >> a[i]; sort(a.begin(), a.end()); int mi = min(n1, n2); int ma = max(n1, n2); int cnt = 0, ans = 0; while(mi > 0){ mi -= a[cnt]; if(mi >= 0){ ans++; cnt++; } } while(ma > 0){ ma -= a[cnt]; if(ma >= 0){ ans++; cnt++; } } printf("%d\n", ans); d--; } }