#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = 3e5+10;
const int inf = 1e15;
ll t,n,m,a[maxn],b[maxn],a1[maxn],a2[maxn],pre[maxn];
bool com(int a,int b){ return a>b; }
signed main()
{
	int t; cin >> t;
	while( t-- )
	{
		cin >> n >> m;
		for(int i=1;i<=n;i++)	scanf("%lld",&a[i]);
		for(int i=1;i<=n;i++)	scanf("%lld",&b[i]);
		a1[0]=a2[0]=0;
		for(int i=1;i<=n;i++)
		{
			if( b[i]==1 )	a1[++a1[0]] = a[i];
			else	a2[++a2[0]] = a[i];
		}
		sort( a1+1,a1+1+a1[0],com );
		sort( a2+1,a2+1+a2[0],com );
		for(int i=1;i<=a2[0];i++)	pre[i] = pre[i-1]+a2[i];
		//ö��ѡ��s��
		int ans = inf,sum=0;
		for(int i=1;i<=a1[0];i++)
		{
			sum+=a1[i];
			if( sum>=m ){ ans=min(i,ans); break; }
			int yu = m-sum;
			int index = lower_bound( pre+1,pre+1+a2[0],yu )-pre;
			if( index==a2[0]+1 )	continue;
			ans = min( ans,i+index*2 );
		}
		int index = lower_bound( pre+1,pre+1+a2[0],m )-pre;
		if( index!=a2[0]+1 )
			ans = min( ans,index*2 );
		if( ans==inf )	cout << -1 << endl;
		else	cout << ans << endl;
	}
}

			  	   		 	    		  		       	