/** * @FileName a.cpp * @Author kanpurin * @Created 2020.06.02 17:36:16 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int main() { int d;cin >> d; while(d--) { int n1,n2;cin >> n1 >> n2; int m;cin >> m; vector v(n1+1,false); v[0] = true; vector a(m); for (int i = 0; i < m; i++) { cin >> a[i]; } sort(a.begin(), a.end()); ll sum = 0; int ans = 0; int now = 0; for (int i = 0; i < m; i++) { sum += a[i]; for (int j = n1; j >= a[i]; j--) { v[j] = v[j] | v[j - a[i]]; if (v[j]) { now = max(now,j); } } if (sum - now <= n2) { ans = i + 1; } } cout << ans << endl; } return 0; }