#include using namespace std; const long long INF = 0x3f3f3f3f3f3f3f3f; long long dp[2010], ndp[2010]; long long a[2010], b[2010]; int main () { int T; scanf("%d", &T); while (T--) { int n; 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(dp, 0x3f, sizeof(dp)); dp[0] = 0; for (int i = 1; i <= n; i++) { memset(ndp, 0x3f, sizeof(ndp)); for (int j = 0; j <= n; j++) { ndp[j] = min(ndp[j], dp[j]); if (dp[j] + a[i] <= b[i]) { ndp[j + 1] = min(ndp[j + 1], dp[j] + a[i]); } } swap(dp, ndp); } for (int i = n; i >= 0; i--) { if (dp[i] != INF) { printf("%d\n", i); break; } } } return 0; }