#include <bits/stdc++.h>
using namespace std;
#define ll  long long
#define Cr7 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll t,n,m,x;
int main()
{
    Cr7
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        vector<ll> a(n);
        for(ll i=0 ; i< n ; i++) cin>>a[i];
        deque<ll> dq[3];
        for(ll i=0 ; i < n ; i++)
        {
            cin>>x;     dq[x].push_back(a[i]);
        }
        sort(dq[1].begin(),dq[1].end());    reverse(dq[1].begin(),dq[1].end());
        sort(dq[2].begin(),dq[2].end());    reverse(dq[2].begin(),dq[2].end());
        ll now=0,Res=0;
        while(now < m )
        {
            ll need=m-now;
            if(dq[1].empty() && dq[2].empty())
                break;
            else if(dq[1].empty())
                now+=dq[2].front(),   dq[2].pop_front() , Res+=2;
            else if(dq[2].empty())
                now+=dq[1].front(),   dq[1].pop_front() , Res+=1;
            else if(dq[1].size() == 1)
            {
                if((dq[1].front() >= need) || (dq[1].front() > dq[2].front()))
                    now+=dq[1].front(),   dq[1].pop_front() , Res+=1;
                else
                    now+=dq[2].front(),   dq[2].pop_front() , Res+=2;
            }
            else
            {
                if(dq[1].front() >= need)
                    now+=dq[1].front(),   dq[1].pop_front() , Res+=1;
                else if(dq[1].front() > dq[2].front())
                    now+=dq[1].front(),   dq[1].pop_front() , Res+=1;
                else if(dq[1][0] + dq[1][1] > dq[2][0])
                    now+=dq[1].front(),   dq[1].pop_front() , Res+=1;
                else
                    now+=dq[2].front(),   dq[2].pop_front() , Res+=2;
            }
        }
        cout<<(now<m ? -1 : Res)<<endl;
    }
    return 0;
}
