#include using namespace std; void solve() { int n1, n2, m; cin >> n1 >> n2 >> m; vector a(m); for (int i = 0; i < m; i++) cin >> a[i]; sort(a.begin(), a.end()); vector dp(n1); dp[0] = true; int tot = 0; int ret = 0; for (int i = 0; i < m; i++) { tot += a[i]; if (tot > n1 + n2) break; bool ck = false; for (int j = n1; j >= a[i]; j--) if (dp[j - a[i]]) dp[j] = true; for (int j = 0; j <= n1; j++) { if (dp[j] && n2 >= tot-j) { ck = true; break; } } if (ck) ++ret; else break; } cout << ret << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while (T--) { solve(); } return 0; }