#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int main() {
    ll t;cin>>t;
    while(t--)
    {
        ll n,m;cin>>n>>m;
        ll a[n],b[n],s=0;
        vector<ll>on;
        vector<ll>tw;
        ll one=0,two=0;
        for(ll i=0;i<n;i++) {cin>>a[i];s+=a[i];}
        for(ll i=0;i<n;i++) {cin>>b[i];if(b[i]==1) {on.push_back(a[i]);one++;}else {tw.push_back(a[i]);two++;}}
        sort(on.begin(),on.end());
        sort(tw.begin(),tw.end());
        ll mem=0;
        
        ll i=one-1,j=two-1,res=0;
        while(mem<m && i>=0 && j>=0)
        {
            
            if(on[i]+mem>=m) {res+=1;mem+=on[i];i--;}
            else if(i>0)
            {
                if(on[i]+on[i-1]>tw[j])
                {
                    res+=1;
                    mem+=(on[i]);
                    i-=1;
                }
                else
                {
                    res+=2;
                    mem+=tw[j];
                    j-=1;
                }
            }
            else if(i==0)
            {
                if(tw[j]>on[i])
                {
                    res+=2;mem+=tw[j];
                    j--;
                }
                else 
                {
                    mem+=on[i];i--;res+=1;
                }
            }
        }
        if(mem<m)
        {
            if(i<0 && j>=0)
            {
                while(j>=0 && mem<m)
                {
                    mem+=tw[j];res+=2;
                    j--;
                }
                
            }
            else if(i>=0 && j<0)
            {
                while(i>=0 && mem<m)
                {
                    mem+=on[i];res+=1;
                    i--;
                }
            }
        }
        if(mem>=m) cout<<res<<endl;
        else cout<<-1<<endl;
    }
}