#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
 
    ll modPow(ll a, ll b){
        if(b==0)
            return 1LL;
        if(b==1)
            return a%M;
        ll res=1;
        while(b){
            if(b%2==1)
                res=mul(res,a);
            a=mul(a,a);
            b=b/2;
        }
        return res;
    }
 
    void solve (){
        ll n,m;
        cin>>n>>m;
        vector<int>a(n);
        vector<int>b(n);
        ll sp=0;
        for(int i=0;i<n;i++) cin>>a[i],sp+=a[i];
        for(int i=0;i<n;i++) cin>>b[i];
        if(sp<m){
            cout<<-1<<"\n";
            return;
        }
        vector<int>c,d;
        for(int i=0;i<n;i++){
            if(b[i]==1) c.push_back(a[i]);
            else d.push_back(a[i]);
        }
        // a has for 1s value and b has for 2s value
        sort(c.rbegin(),c.rend());
        sort(d.rbegin(),d.rend());
        ll ans=1e9;
        int x=c.size();
        int y=d.size();
        vector<ll>ok(y+1);
        for(int i=0;i<y;i++){
            ok[i+1]=ok[i]+d[i];
        }
        ll total=0;
        int pos=lower_bound(ok.begin(),ok.end(),m)-ok.begin();
        if(pos<y+1){
            ans=min(ans,pos*2LL);
        }
        for(int i=0;i<x;i++){
            ll count=i+1;
            total+=c[i];
            ll left=m-total;
            if(left>0){
                pos=lower_bound(ok.begin(),ok.end(),left)-ok.begin();
                if(pos>=y+1) continue;
                count+=(pos*2);
            }
            ans=min(ans,count);
        }
        cout<<ans<<"\n";
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }