#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 dp1(n1+1), dp2(n2+1); dp1[0] = dp2[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 > 0; j--) if (j - a[i] >= 0) dp1[j] |= dp1[j - a[i]]; for (int j = n2; j > 0; j--) if (j - a[i] >= 0) dp2[j] |= dp2[j - a[i]]; for (int j = 0; j <= n1; j++) { if (dp1[j] && 0 <= tot-j && tot-j <= n2 && dp2[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; }