#include<bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define int long long
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pll;
LL tc, n, m, a[200200], b[200200], c[200200], d[200200];
int32_t main()
{
    scanf("%lld", &tc);
    while(tc--)
    {
        scanf("%lld %lld", &n, &m);
        for(int i=0; i<n; i++) scanf("%lld", &a[i]);
        for(int i=0; i<n; i++) scanf("%lld", &b[i]);
        LL cnt1=0, cnt2=0;
        for(int i=0; i<n; i++)
        {
            if(b[i]==1) c[cnt1++]=a[i];
            else d[cnt2++]=a[i];
        }
        sort(c, c+cnt1);
        sort(d, d+cnt2);
        LL k1=0, k2=0, cur=0, ans=0;
        while(k1<cnt1 || k2<cnt2)
        {
            if(cur>=m) break;
            if(k1<cnt1 && (2*c[cnt1-1-k1]>=d[cnt2-1-k2] || k2>=cnt2 || cur+c[cnt1-1-k1]>=m))
                cur+=c[cnt1-1-k1], ans+=1, k1++;
            else cur+=d[cnt2-1-k2], ans+=2, k2++;
        }
        k1--;
        LL ans1=ans;
        while(k2<=cnt2)
        {
            while(cur-c[cnt1-1-k1]>=m && k1>=0) cur-=c[cnt1-1-k1], ans1-=1, k1--;
            ans=min(ans, ans1);
            cur+=d[cnt2-1-k2], ans1+=2, k2++;
        }
        if(cur<m) printf("-1\n");
        else printf("%lld\n", ans);
    }
}
