#include using namespace std; #define ll long long const int N = 2005; int T, n; ll a[N], b[N], f[N][N]; int main() { scanf("%d", &T); while(T--){ scanf("%d", &n); for(int i=1; i<=n; ++i) scanf("%lld", a+i); for(int i=1; i<=n; ++i) scanf("%lld", b+i), b[i]+=b[i-1]; memset(f, 0x3f, sizeof f), f[0][0]=0; for(int i=1; i<=n; ++i) for(int j=0; j<=i; ++j){ f[i][j]=f[i-1][j]; if(j>0 && f[i-1][j-1]+a[i]<=b[i]) f[i][j]=min(f[i][j], f[i-1][j-1]+a[i]); } for(int i=n; ~i; --i) if(f[n][i]<1e15){ printf("%d\n", i); break; } } return 0; }