#include #define ll long long using namespace std; int T,n; ll dp[2005][2005],a[2005],b[2005]; int read(){ int x=0;char ch=getchar(); while(!isdigit(ch)) ch=getchar(); while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); return x; } void print(ll x){ if(x>=10) print(x/10); putchar(x%10+'0'); } int main(){ T=read(); while(T--){ n=read(); for(int i=0;i<=n;i++){ for(int j=0;j<=n;j++) dp[i][j]=1e18; } for(int i=1;i<=n;i++) a[i]=read(); for(int i=1;i<=n;i++) b[i]=read(),b[i]+=b[i-1]; dp[0][0]=0; for(int i=1;i<=n;i++){ for(int j=0;j<=i;j++){ dp[i][j]=min(dp[i][j],dp[i-1][j]); if(j){ if(dp[i-1][j-1]+a[i]<=b[i]) dp[i][j]=min(dp[i][j],dp[i-1][j-1]+a[i]); } } } for(int i=n;i>=0;i--){ if(dp[n][i]!=1e18){ print(i),puts(""); break; } } } return 0; }