#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265
ll mod = 1000000007;
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
int main()  
{
    #ifndef ONLINE_JUDGE
        freopen("input1.txt","r",stdin);
        freopen("output1.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll t;
    cin >> t;
    while(t--)  {
        ll n, m;
        cin >> n >> m;
        vector<ll> one, two;
        vector<ll> v1(n), v2(n);
        ll sum = 0;
        for(int i = 0; i < n; i++)  {
            cin >> v1[i];
            sum += v1[i];
        }
        for(int i = 0; i < n; i++)  {
            cin >> v2[i];
            if(v2[i] == 1)  {
                one.push_back(v1[i]);
            }
            else    {
                two.push_back(v1[i]);
            }
        }
        sort(one.rbegin(), one.rend());
        sort(two.rbegin(), two.rend());
        if(sum < m) {
            cout << "-1" << "\n";
            continue;
        }
        ll idx = 0;
        ll sz1 = one.size(), sz2 = two.size();
        sum = 0;
        while(idx < sz1 && sum < m) {
            sum += one[idx];
            idx++;
        }
        ll ans = 3*n;
        if(sum >= m)    {
            ans = idx;
        }
        ll idx1 = idx, idx2 = 0;
        //reverse(one.begin(), one.end());
        while(idx2 < sz2)   {
            sum += two[idx2];
            idx2++;
            while(idx1 > 0 && sum - one[idx1 - 1] >= m)    {
                sum -= one[idx1 - 1];
                idx1--;
            }
            if(sum >= m)    {
                ans = min(ans, idx2*2 + idx1);
            }
        }
        if(ans > 2*n)   {
            cout << "-1" << "\n";
        }
        else    {
            cout << ans << "\n";
        }
    }
}
    
    

