#include using namespace std; typedef long long ll; typedef pair pii; #define fir first #define sec second #define rep(i,a,b) for (int i = (a); i <= (b); ++ i) #define rrp(i,a,b) for (int i = (a); i >= (b); -- i) #define gc() getchar() template inline void read(tp& x) { x = 0; char tmp; bool key = 0; for (tmp = gc(); !isdigit(tmp); tmp = gc()) key = (tmp == '-'); for (; isdigit(tmp); tmp = gc()) x = (x << 3) + (x << 1) + (tmp ^ '0'); if (key) x = -x; } template inline void ckmn(tp& x,tp y) { x = x < y ? x : y; } template inline void ckmx(tp& x,tp y) { x = x < y ? y : x; } const int N = 2010; int n; ll va[N], vb[N], dp[N][N]; void solve() { read(n); rep (i, 1, n) read(va[i]); rep (i, 1, n) read(vb[i]); rep (i, 2, n) vb[i] = vb[i] + vb[i-1]; memset(dp, 0x3f, sizeof dp); dp[0][0] = 0; rep (i, 1, n) { rep (j, 0, n) dp[i][j] = dp[i-1][j]; rep (j, 0, n) if (dp[i-1][j] + va[i] <= vb[i]) { dp[i][j+1] = min(dp[i][j+1], dp[i-1][j] + va[i]); } } int ans = 0; rep (j, 0, n) if (dp[n][j] < 0x3f3f3f3f3f3f3f3f) { ans = max(ans, j); } printf("%d\n", ans); } int main() { int T; read(T); while (T --) solve(); return 0; }