#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i,n) for(int (i)=0;(i)<(n);(i)++) #define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++) #define RREP(i,a) for(int (i)=(a)-1;(i)>=0;(i)--) #define FORR(i,a,b) for(int (i)=(a)-1;(i)>=(b);(i)--) #define PI acos(-1.0) #define DEBUG(C) cout< #define VII vector #define VL vector #define VLL vector #define VD vector #define VDD vector #define PII pair #define PDD pair #define PLL pair #define VPII vector #define ALL(a) (a).begin(),(a).end() #define SORT(a) sort(ALL(a)) #define REVERSE(a) reverse(ALL(a)) #define MP make_pair #define FORE(a,b) for(auto &&a:b) using namespace std; typedef long long LL; typedef unsigned long long ULL; const int INF=1e9; const int MOD=INF+7; int solve(){ int n[2]; REP(i,2) cin >> n[i]; int nsum=n[0]+n[1]; int m; cin >> m; VI a(m),asum(m); REP(i,m){ cin >> a[i]; if(i==0) asum[i]=a[i]; else asum[i]=asum[i-1]+a[i]; } SORT(a); VII dp(m+1,VI(n[0]+1,0)); //dp[i][j] i人目,n1の残り長さj dp[0][n[0]]=1; REP(i,m){ bool f=false; RREP(j,n[0]+1){ if(!dp[i][j]) continue; if(j>=a[i]){ dp[i+1][j-a[i]]=1; f=true; } if(nsum-asum[i]>=a[i]){ dp[i+1][j]=1; f=true; } } if(!f) return i; } return m; } int main(void){ int d; cin >> d; REP(i,d){ cout << solve() << endl; } }