#include #include #include #include #define RI register int #define int long long using namespace std; int Mn[2005]; int a[2005]; int b[2005]; signed main() { //freopen("a.in", "r", stdin); int T; scanf("%lld", &T); while (T--) { int n; scanf("%lld", &n); for (RI i = 1; i <= n; ++i) scanf("%lld", &a[i]); for (RI i = 1; i <= n; ++i) scanf("%lld", &b[i]); for (RI i = 1; i <= n; ++i) b[i] += b[i - 1]; memset(Mn, 0x3f, sizeof(Mn)); Mn[0] = 0; for (RI i = 1; i <= n; ++i) for (RI j = i; j; --j) if (Mn[j - 1] + a[i] <= b[i]) Mn[j] = min(Mn[j], Mn[j - 1] + a[i]); int ans = 0; for (RI i = n; ~i; --i) if (Mn[i] != 0x3f3f3f3f3f3f3f3f) { printf("%lld\n", i); break; } } return 0; }