#include using namespace std; #define _p(...) (void)printf(__VA_ARGS__) #define forr(x,arr) for(auto&& x:arr) #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(int i=int(a);i=int(a);i--) #define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__) #define ALL(x) (x).begin(), (x).end() #define BIT(n) (1LL<<(n)) #define SZ(x) ((int)(x).size()) #define fst first #define snd second typedef vector vi;typedef vector vvi;typedef pair pii;typedef vector vpii; typedef long long ll; template inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } unordered_set s[2]; void Main() { int N1, N2, M; scanf("%d%d%d", &N1, &N2, &M); vi A(M); rep(i, M) scanf("%d", &A[i]); sort(ALL(A)); const ll D = 1000000; s[1].clear(); s[1].insert(N1 * D + N2); rep(i, M) { int a = A[i]; s[i%2].clear(); bool ok = 0; forr(x, s[(i+1)%2]) { if (x >= a * D) { s[i%2].insert(x - a * D); ok = 1; } if (x % D >= a) { s[i%2].insert(x - a); ok = 1; } } if (!ok) { _p("%d\n", i); return; } } _p("%d\n", M); } int main() { int T; scanf("%d", &T); while (T--) Main(); return 0; }