#include<bits/stdc++.h>                                                   //---------------------------------------------------------------

# define ll long long
# define mod 1000000007
# define MAX 100005
# define PI 3.141592653589793238                                                                                  //shortcut keys

# define pb push_back
# define mp make_pair
# define all(x) x.begin(),x.end()
# define fr(i,a,b) for(int i=a;i<=b;i++)

# define decimal(k) fixed<<setprecision(k)
# define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);        //---------------------------------------------------------------
using namespace std;

int main()
{
	fast;
	int T;cin>>T;
	while(T--){
		ll n,m;cin>>n>>m;
		int a[n+1],b[n+1];
		fr(i,1,n)cin>>a[i];
		fr(i,1,n)cin>>b[i];
		vector<ll> one,two;
		one.pb(0);
		two.pb(0);
		fr(i,1,n){
			if(b[i]==1)one.pb(a[i]);
			else two.pb(a[i]);
		}
		sort(one.begin()+1,one.end());
		reverse(one.begin()+1,one.end());
		sort(two.begin()+1,two.end());
		reverse(two.begin()+1,two.end());
		ll ans=0,cnts=0;
		int n1=one.size(),n2=two.size();
		fr(i,1,n1-1)one[i]+=one[i-1];
		fr(i,1,n2-1)two[i]+=two[i-1];
		ans=1000000004;
		bool ok=false;
		fr(i,0,n1-1){
			ll an=i;
			ll x=one[i];
			ll y=m-one[i];
			ll pos=lower_bound(all(two),y)-two.begin();
			if(pos>=n2)continue;
			an+=2*pos;
			ok=true;
			ans=min(ans,an);
		}
		if(!ok)cout<<-1<<'\n';
		else
		cout<<ans<<'\n';
		
	
	}


	return 0;
}



