#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define me(a,x) memset(a,x,sizeof(a))
#define sf scanf
#define pf printf
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define gcd __gcd
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const ll llINF=9223372036854775807;
const int maxn=2e5+10;
const double pi=acos(-1.0);
using namespace std;
ll n,m;
ll a[maxn],b[maxn],num[maxn];

bool cmp(ll x,ll y){
	return x>y;
} 

void solve()
{
	int x;
	cin>>n>>m;
	ll sum=0;
	rep(i,1,n){
		cin>>num[i];
		sum+=num[i];
	}
	int cnt1=1,cnt2=1;
	rep(i,1,n){
		cin>>x;
		if(x==1){
			a[cnt1++]=num[i];
		}else{
			b[cnt2++]=num[i];
		}
	}
	if(sum<m){
		cout<<-1<<endl;
		return ;
	}
	sort(a+1,a+cnt1,cmp);
	sort(b+1,b+cnt2,cmp);
	a[0]=b[0]=a[cnt1]=b[cnt2]=0;
	rep(i,1,cnt1-1){
		a[i]+=a[i-1];
	}
	rep(i,1,cnt2-1){
		b[i]+=b[i-1];
	}
	int res=INF;
	rep(i,0,cnt1-1){
		ll tmp=m-a[i];
		int id=lower_bound(b+1,b+cnt2,tmp)-b;
		if(a[i]+b[id]>=m)
		res=min(res,i+id*2);
		id--;
		if(a[i]+b[id]>=m){
			res=min(res,i+id*2);
		}
//		cout<<"!"<<i<<" "<<id<<" "<<res<<endl;
	}
	cout<<res<<endl;
}

int main()
{
	IOS;
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}