#include using namespace std; #define ll long long const int maxn = 2020; int a[maxn], b[maxn]; ll sb[maxn], dp[maxn][maxn]; int main(void) { //freopen("g.in","r",stdin); int T; scanf("%d",&T); while (T--) { int n; scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&a[i]); for (int i=1;i<=n;i++) scanf("%d",&b[i]); for (int i=1;i<=n;i++) sb[i]=sb[i-1]+b[i]; memset(dp,0x3f,sizeof(dp)); dp[0][0]=0; for (int i=1;i<=n;i++) { for (int j=0;j<=i;j++) { dp[i][j]=dp[i-1][j]; if (j>0 && dp[i-1][j-1]+a[i] <= sb[i]) { dp[i][j] = min(dp[i][j], dp[i-1][j-1]+a[i]); } } } int ans = 0; for (int i=0;i<=n;i++) if (dp[n][i]<=1e18) ans=i; printf("%d\n",ans); } return 0; }