# include using namespace std; namespace Base{ # define mr make_pair typedef long long ll; typedef double db; const int inf = 0x3f3f3f3f, INF = 0x7fffffff; const ll infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll; template void read(T &x){ x = 0; int fh = 1; double num = 1.0; char ch = getchar(); while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); } while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); } if (ch == '.'){ ch = getchar(); while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();} } x = x * fh; } template void chmax(T &x, T y){x = x < y ? y : x;} template void chmin(T &x, T y){x = x > y ? y : x;} } using namespace Base; const int N = 2020; ll a[N], b[N], f[N][N]; int n; int main(){ int T; read(T); while (T--){ read(n); for (int i = 1; i <= n; i++) read(a[i]); for (int i = 1; i <= n; i++){ read(b[i]); b[i] = b[i - 1] + b[i]; } for (int i = 0; i <= n; i++) for (int j = 1; j <= n; j++) f[i][j] = infll; int ans = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= i; j++){ f[i][j] = f[i - 1][j]; if (f[i - 1][j - 1] + a[i] <= b[i]) f[i][j] = min(f[i][j], f[i - 1][j - 1] + a[i]); if (f[i][j] != infll) ans = max(ans, j); } cout << ans << endl; } return 0; }