#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define ld long double
const ll MOD=998244353;
const ll LMAX=1e18;
const ll MAX=2e5+5;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main() {
#ifndef ONLINE_JUDGE
  	//for getting input from input.txt
   	freopen("input.txt","r",stdin);
   	//for writing output  to output.txt
   	freopen("output.txt","w",stdout);
#endif

    ios_base::sync_with_stdio();
    cin.tie();
    cout.tie();
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,m,sum_1=0,sum_2=0;
        cin>>n>>m;
        vector<ll> a(n);
        vector<ll> one;
        vector<ll> two;

        for(ll i=0;i<n;i++)
        {
            cin>>a[i];
        }
        for(ll i=0;i<n;i++)
        {
            ll b;
            cin>>b;
            if(b==1)
            {
                one.push_back(a[i]);
            }
            else
            {
                two.push_back(a[i]);
                sum_2+=a[i];
            }
        }
        sort(one.rbegin(),one.rend());
        sort(two.rbegin(),two.rend());
        ll r=(ll)two.size()-1;
        ll ans=INT_MAX;

        for(ll i=0;i<=one.size();i++)
        {
            while(r>=0 && (sum_1+sum_2-two[r])>=m)
            {
                sum_2=sum_2-two[r];
                r--;
            }
            if((sum_1+sum_2)>=m)
            {
                ans=min(ans,2*(r+1)+i);
                //cout<<i<<": "<<ans<<" ";
            }
            if(i==one.size())
            {
                break;
            }
            sum_1=sum_1+one[i];
        }

        cout<<(ans==INT_MAX ? -1:ans)<<endl;
    }
#ifdef _DEBUG
    cerr << "TIME = " << clock() — tt << endl;
    tt = clock();
#endif
    return 0;
}
    /*taskkill -im .exe -f*/

