#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
using namespace std;
const int sz = 1e6 + 9;
const ll mod =  1e9 + 7;
const ll inf = 1e18;
const double eps = 1e-9;
void test()
{
    int n,m;cin>>n>>m;
    ll x[n],y[n];
    ll sum = 0;
    vector<ll> twoes,ones;
    for(int i=0;i<n;i++)
    {
        cin>>x[i];
        sum+=x[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>y[i];
        if(y[i]==1)
            ones.pb(x[i]);
        else
            twoes.pb(x[i]);
    }
    if(sum < m) {
        cout << "-1\n";
        return;
    }
    ll ans = 0;
    sum = m;
    sort(ones.rbegin(),ones.rend());
    sort(twoes.rbegin(),twoes.rend());
    int i = 0,j = 0;
    if(ones.empty())
    {
        while(sum > 0)
            sum-=twoes[i++],ans+=2;
        cout<<ans<<"\n";return;
    }
    else if(twoes.empty())
    {
        while(sum > 0)
            sum-=ones[i++],ans++;
        cout<<ans<<"\n";return;
        return;
    }
    while(sum > 0)
    {
        if(sum <= ones[j] && j < ones.size())
        {
            ans++;break;
        }
        if(twoes[i] >= ones[j] + ones[j + 1] && i < twoes.size() && j < ones.size() - 1)
        {
            sum-=twoes[i++],ans+=2;
        }
        else if(i < twoes.size() && j < ones.size() - 1)
            sum -= ones[j++],ans++;
        else if(i < twoes.size() && j==ones.size() - 1)
        {
            if(ones[j] > twoes[i])
                sum-=ones[j++],ans++;
            else
                sum-=twoes[i++],ans+=2;
        }
        else if(j < ones.size() && i==twoes.size())
        {
            while(sum > 0 && j < ones.size()) { sum -= ones[j++], ans++; }
        }
        else if(i < twoes.size() && j==ones.size())
        {
            while(sum > 0 && i < twoes.size()) { sum -= twoes[i++], ans += 2; }
        }
    }
    cout<<ans<<"\n";
}

int main(){
    int cases = 1;
    cin>>cases;
    while(cases--)
        test();
}