﻿#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
#define ll long long int
const int MAXN = 2e5 + 10;
const int INF=0x3f3f3f3f;
const ll LINF=0x3f3f3f3f3f3f3f3f;
const int NINF=-INF-1;
const ll mod=1e9+7;
#define PI acos(-1.0)
int T,n,m;
int a[MAXN],b[MAXN];
int main()
{ 	scanf("%d",&T);
	while(T--)
{	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	scanf("%d",&b[i]);
	priority_queue<int> one,two;
	for(int i=1;i<=n;i++)
	{	if(b[i]==1)
		one.push(a[i]);
		else two.push(a[i]);	
	}
	ll ans=0;
	while(m>0)
	{	if(one.empty()&&two.empty())
			break;
			if(one.size())
			{	int x1=one.top();
				if(m-x1<=0)
				{	m=m-x1;
					ans++;
					break;
				}
						
			}

		if(one.size()>=2&&two.size())
		{	int x1=one.top();
			one.pop();
			int x2=one.top();
			one.pop();
			int y=two.top();
			two.pop();
			if(x1+x2>=y)
			{	ans+=1;
				m=m-x1;
				two.push(y);
				one.push(x2);
			}
			else{
			ans+=2;
			m-=y;
			one.push(x1);
			one.push(x2);
			}
			
		}
		else if(two.size())
		{	int y=two.top();
			two.pop();
			ans+=2;
			m-=y;
			
		}
		else{
			int x1=one.top();
			one.pop();
			m-=x1;
			ans++;
			
		}
		
		
		
	}
	if(m>0)
	ans=-1;
	cout<<ans<<endl;
		
		
		
}


    return 0;
}
