#include using std::cin; using std::cout; typedef long long ll; typedef std::pair pr; const int N = 2054; const ll INF64 = 0x3f3f3f3f3f3f3f3fll; int n; int a[N], b[N]; ll B[N], f[N]; inline void down(ll &x, const ll y) {x > y ? x = y : 0;} void work() { int i, j; cin >> n; for (i = 1; i <= n; ++i) cin >> a[i]; for (i = 1; i <= n; ++i) cin >> b[i], B[i] = B[i - 1] + b[i]; memset(f, 63, sizeof f), *f = 0; for (i = 1; i <= n; ++i) { if (a[i] > B[i]) continue; for (j = n; j >= 0; --j) if (f[j] <= B[i] - a[i]) down(f[j + 1], f[j] + a[i]); } for (i = n; i && f[i] >= INF64; --i); cout << i << '\n'; } int main() { int T; std::ios::sync_with_stdio(false), cin.tie(NULL); for (cin >> T; T; --T) work(); return 0; }