#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template static void amin(T &x, U y) { if(y < x) x = y; } template static void amax(T &x, U y) { if(x < y) x = y; } int main() { int T; scanf("%d", &T); for(int ii = 0; ii < T; ++ ii) { int n1; int n2; scanf("%d%d", &n1, &n2); int m; scanf("%d", &m); vector a(m); for(int i = 0; i < m; ++ i) scanf("%d", &a[i]); sort(a.begin(), a.end()); vector dp(n1 + 1, INF); dp[0] = 0; int i; for(i = 0; i < m; ++ i) { int t = a[i]; for(int j = n1; j >= 0; -- j) { int x = dp[j]; if(x == INF) continue; if(j + t <= n1) amin(dp[j + t], x); dp[j] = x + t <= n2 ? x + t : INF; } if(count(dp.begin(), dp.end(), INF) == n1 + 1) break; } printf("%d\n", i); } return 0; }