#include using namespace std; #define int long long // <-----!!!!!!!!!!!!!!!!!!! #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--) #define all(a) (a).begin(),(a).end() typedef long long ll; typedef pair Pii; typedef tuple TUPLE; typedef vector V; typedef vector VV; typedef vector VVV; typedef vector> Graph; const int inf = 1e9; const int mod = 1e9 + 7; signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int d; cin >> d; rep(_, d) { int n1, n2; cin >> n1 >> n2; int m; cin >> m; V a(m); rep(i, m) cin >> a[i]; sort(all(a)); a.emplace_back(inf); m++; const int MAX = n1 + n2 + 1; // bool dp1[MAX] = {}; vector dp1(MAX); dp1[n1] = true; int sm1 = n1 + n2; // rep(i, MAX) { // cout << setw(2) << i << " "; // } // cout << endl; rep(i, m) { // bool dp2[MAX] = {}; vector dp2(MAX); bool updated = false; int sm2 = sm1 - a[i]; rep(j, MAX) { if (!dp1[j]) continue; if (j - a[i] >= 0) { dp2[j - a[i]] = true; updated = true; } if (sm2 - j >= 0) { dp2[j] = true; updated = true; } } // rep(i, MAX) { // cout << setw(2) << dp2[i] << " "; // } // cout << endl; if (!updated) { cout << i << endl; break; } dp1 = dp2; sm1 = sm2; } } }