#include<bits/stdc++.h>
#define int int64_t

using namespace std;

const int N = 1e6+1;
const int mod = 1000000007;
int fact[N];
int invFact[N];


int gcd(int a,int b){
	if(a==0)
		return b;
	
	return gcd(b%a, a);
}

int fast_pow(int a, int p) {
    int res = 1;
    while (p) {
        if (p % 2 == 0) {
            a = (a * a) % mod;
            p /= 2;
        } else {
            res = (res * a) % mod;
            p--;
        }
    }
    return res;
}

int C(int n, int k) {
    if (k > n) {
        return 0;
    }
    return fact[n] * invFact[k] % mod * invFact[n - k] % mod;
}

bool comp(pair<int,int> p1, pair<int,int> p2){
	if(p1.first < p2.first)
		return true;
	else
		if( p1.second > p2.second)
			return true;
		
	return false;
}



void solve(){
	
}





signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	/*fact[0] = invFact[0] = 1;
    for (int i = 1; i < N; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
        invFact[i] = fast_pow(fact[i], mod - 2);
    }*/
 
	int t = 1;
	cin>>t;
	
	while(t--){
		int n,m;
		cin>>n>>m;
		
		vector<int> a(n);
		vector<int> b(n);
		
		for(int i =0 ;i < n; i++)
			cin>>a[i];
			
		for(int i = 0; i < n ; i++)
			cin>>b[i];
			
		vector<int> ones,twos;
		
		for(int i = 0;i < n;i++){
			if(b[i] == 2) twos.push_back(a[i]);
			else	ones.push_back(a[i]);
		}

		sort(twos.begin(), twos.end(), greater<int>());
		sort(ones.begin(), ones.end(), greater<int>());
		
		
		vector<int> prf1(ones.size()+1);
		vector<int> prf2(twos.size()+1);
	
		
		prf1[0] = 0;
		
		for(int i = 1;i <= ones.size(); i++){
			prf1[i] = prf1[i-1] + ones[i-1];
		}
		
		prf2[0] = 0;
		
		for(int i = 1;i <= twos.size(); i++){
			prf2[i] = prf2[i-1] + twos[i-1];
		}
		int ans = INT_MAX;
		for(int i = 0;i <=  ones.size(); i++){
			
			int x,y;
		
			int toFind = m;
			if(i)
				toFind -= prf1[i];
			 
			x = i;
			y = lower_bound(prf2.begin(), prf2.end(), toFind) - prf2.begin();
			
		//	cout<<y<<"\n";
			if(y > twos.size())
				continue;
			
		//	cout<<x<<" "<<y<<"\n";
			ans = min(ans, x+2*y);
		}
		
		if(ans == INT_MAX) cout<<"-1\n";
		else cout<<ans<<"\n";
		
	}
}