#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int INF = 987654321;
int n,w;
int cost[10005][2];
int cache[10005][2];
int get_dp(int idx, int type)
{
if (idx >=n) return 0;
int& ret = cache[idx][type];
if(ret != -1) return ret;
if (idx == n-1 && type == 0) {
if(cost[n-1][0] + cost[n-1][1] <= w){
return 1;
}
return 2;
}
if (idx == n-1 && type == 1)
return 1;
ret = INF;
if(type == 0){
if(cost[idx][0] + cost[idx][1] <= w){
ret = min(ret, 1 + get_dp(idx+1, 0));
}
if(cost[idx][0] + cost[idx+1][0] <= w){
if(cost[idx][1] + cost[idx+1][1] <= w){
ret = min(ret, 2 + get_dp(idx+2,0));
}
ret = min(ret, 2 + get_dp(idx+1,1));
}
ret = min(ret, 1 + get_dp(idx,1));
}else if(type == 1){
if(cost[idx][1] + cost[idx+1][1] <= w){
if(cost[idx+1][0] + cost[idx+2][0] <= w){
ret = min(ret, 2 + get_dp(idx+2,1));
}
ret = min(ret, 2 + get_dp(idx+2,0));
}
ret = min(ret, 1 + get_dp(idx+1,0));
}
return ret;
}
int main()
{
int t;
for(scanf("%d",&t);t;--t){
memset(cache,-1,sizeof(cache));
memset(cost,0,sizeof(cost));
int ans = INF;
scanf("%d%d",&n,&w);
for(int j=0;j<2;++j){
for(int i=0;i<n;++i){
scanf("%d",&cost[i][j]);
}
}
ans = min(ans, get_dp(0,0));
int c00 = cost[0][0];
int cn0 = cost[n-1][0];
int c01 = cost[0][1];
int cn1 = cost[n-1][1];
if(n==1){
printf("%d\n",ans);
continue;
}
memset(cache,-1,sizeof(cache));
if (c00 + cn0 <= w && c01 + cn1 <= w) {
cost[0][0] = cost[n-1][0] = cost[0][1] = cost[n-1][1] = INF;
ans = min(ans, get_dp(0,0) - 2);
cost[0][0] = c00;
cost[n-1][0] = cn0;
cost[0][1] = c01;
cost[n-1][1] = cn1;
}
memset(cache, -1, sizeof(cache));
if (c00 + cn0 <= w) {
cost[0][0] = cost[n-1][0] = INF;
ans = min(ans, get_dp(0,0) - 1);
cost[0][0] = c00;
cost[n-1][0] = cn0;
}
memset(cache, -1, sizeof(cache));
if (c01 + cn1 <= w) {
cost[0][1] = cost[n-1][1] = INF;
ans = min(ans, get_dp(0,0) - 1);
cost[0][1] = c01;
cost[n-1][1] = cn1;
}
printf("%d\n",ans);
}
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxhbGdvcml0aG0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBJTkYgPSA5ODc2NTQzMjE7CmludCBuLHc7CgppbnQgY29zdFsxMDAwNV1bMl07CmludCBjYWNoZVsxMDAwNV1bMl07CgppbnQgZ2V0X2RwKGludCBpZHgsIGludCB0eXBlKQp7CiAgICAgICAgaWYgKGlkeCA+PW4pIHJldHVybiAwOwogICAgICAgIAogICAgICAgIGludCYgcmV0ID0gY2FjaGVbaWR4XVt0eXBlXTsKICAgICAgICBpZihyZXQgIT0gLTEpIHJldHVybiByZXQ7CiAgICAgICAgaWYgKGlkeCA9PSBuLTEgJiYgdHlwZSA9PSAwKSB7CiAgICAgICAgICAgICAgICBpZihjb3N0W24tMV1bMF0gKyBjb3N0W24tMV1bMV0gPD0gdyl7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcmV0dXJuIDI7CiAgICAgICAgfQogICAgICAgIGlmIChpZHggPT0gbi0xICYmIHR5cGUgPT0gMSkgCiAgICAgICAgICAgICAgICByZXR1cm4gMTsKICAgICAgICAgICAgICAgIAogICAgICAgIHJldCA9IElORjsKICAgICAgICBpZih0eXBlID09IDApewogICAgICAgICAgICAgICAgaWYoY29zdFtpZHhdWzBdICsgY29zdFtpZHhdWzFdIDw9IHcpewogICAgICAgICAgICAgICAgICAgICAgICByZXQgPSBtaW4ocmV0LCAxICsgZ2V0X2RwKGlkeCsxLCAwKSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZihjb3N0W2lkeF1bMF0gKyBjb3N0W2lkeCsxXVswXSA8PSB3KXsKICAgICAgICAgICAgICAgICAgICAgICAgaWYoY29zdFtpZHhdWzFdICsgY29zdFtpZHgrMV1bMV0gPD0gdyl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0ID0gbWluKHJldCwgMiArIGdldF9kcChpZHgrMiwwKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgcmV0ID0gbWluKHJldCwgMiArIGdldF9kcChpZHgrMSwxKSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICByZXQgPSBtaW4ocmV0LCAxICsgZ2V0X2RwKGlkeCwxKSk7CiAgICAgICAgICAgICAgICAKICAgICAgICB9ZWxzZSBpZih0eXBlID09IDEpewogICAgICAgICAgICAgICAgaWYoY29zdFtpZHhdWzFdICsgY29zdFtpZHgrMV1bMV0gPD0gdyl7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmKGNvc3RbaWR4KzFdWzBdICsgY29zdFtpZHgrMl1bMF0gPD0gdyl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0ID0gbWluKHJldCwgMiArIGdldF9kcChpZHgrMiwxKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgcmV0ID0gbWluKHJldCwgMiArIGdldF9kcChpZHgrMiwwKSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICByZXQgPSBtaW4ocmV0LCAxICsgZ2V0X2RwKGlkeCsxLDApKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKfQppbnQgbWFpbigpCnsKICAgICAgICBpbnQgdDsKICAgICAgICBmb3Ioc2NhbmYoIiVkIiwmdCk7dDstLXQpewogICAgICAgICAgICAgICAgbWVtc2V0KGNhY2hlLC0xLHNpemVvZihjYWNoZSkpOwogICAgICAgICAgICAgICAgbWVtc2V0KGNvc3QsMCxzaXplb2YoY29zdCkpOwogICAgICAgICAgICAgICAgaW50IGFucyA9IElORjsKICAgICAgICAgICAgICAgIHNjYW5mKCIlZCVkIiwmbiwmdyk7CiAgICAgICAgICAgICAgICBmb3IoaW50IGo9MDtqPDI7KytqKXsKICAgICAgICAgICAgICAgICAgICAgICAgZm9yKGludCBpPTA7aTxuOysraSl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2NhbmYoIiVkIiwmY29zdFtpXVtqXSk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGFucyA9IG1pbihhbnMsIGdldF9kcCgwLDApKTsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgaW50IGMwMCA9IGNvc3RbMF1bMF07CiAgICAgICAgICAgICAgICBpbnQgY24wID0gY29zdFtuLTFdWzBdOwogICAgICAgICAgICAgICAgaW50IGMwMSA9IGNvc3RbMF1bMV07CiAgICAgICAgICAgICAgICBpbnQgY24xID0gY29zdFtuLTFdWzFdOwogICAgICAgICAgICAgICAgaWYobj09MSl7CiAgICAgICAgICAgICAgICAgICAgICAgIHByaW50ZigiJWRcbiIsYW5zKTsKICAgICAgICAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBtZW1zZXQoY2FjaGUsLTEsc2l6ZW9mKGNhY2hlKSk7CiAgICAgICAgICAgICAgICBpZiAoYzAwICsgY24wIDw9IHcgJiYgYzAxICsgY24xIDw9IHcpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY29zdFswXVswXSA9IGNvc3Rbbi0xXVswXSA9IGNvc3RbMF1bMV0gPSBjb3N0W24tMV1bMV0gPSBJTkY7CiAgICAgICAgICAgICAgICAgICAgICAgIGFucyA9IG1pbihhbnMsIGdldF9kcCgwLDApIC0gMik7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvc3RbMF1bMF0gPSBjMDA7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvc3Rbbi0xXVswXSA9IGNuMDsKICAgICAgICAgICAgICAgICAgICAgICAgY29zdFswXVsxXSA9IGMwMTsKICAgICAgICAgICAgICAgICAgICAgICAgY29zdFtuLTFdWzFdID0gY24xOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBtZW1zZXQoY2FjaGUsIC0xLCBzaXplb2YoY2FjaGUpKTsKICAgICAgICAgICAgICAgIGlmIChjMDAgKyBjbjAgPD0gdykgewogICAgICAgICAgICAgICAgICAgICAgICBjb3N0WzBdWzBdID0gY29zdFtuLTFdWzBdID0gSU5GOwogICAgICAgICAgICAgICAgICAgICAgICBhbnMgPSBtaW4oYW5zLCBnZXRfZHAoMCwwKSAtIDEpOwogICAgICAgICAgICAgICAgICAgICAgICBjb3N0WzBdWzBdID0gYzAwOwogICAgICAgICAgICAgICAgICAgICAgICBjb3N0W24tMV1bMF0gPSBjbjA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIG1lbXNldChjYWNoZSwgLTEsIHNpemVvZihjYWNoZSkpOwogICAgICAgICAgICAgICAgaWYgKGMwMSArIGNuMSA8PSB3KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvc3RbMF1bMV0gPSBjb3N0W24tMV1bMV0gPSBJTkY7CiAgICAgICAgICAgICAgICAgICAgICAgIGFucyA9IG1pbihhbnMsIGdldF9kcCgwLDApIC0gMSk7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvc3RbMF1bMV0gPSBjMDE7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvc3Rbbi0xXVsxXSA9IGNuMTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHByaW50ZigiJWRcbiIsYW5zKTsKICAgICAgICB9Cn0K