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

//#define m 1000000007
#define geti(n) scanf("%d", &n)
#define pb push_back
using pil = pair<ll, ll>;
using pii = pair<int, int>;
using pid = pair<double, double>;
void solve()
{
    ll n, m;
    cin >> n >> m;

    vector<ll> d1, d2;
    ll a[n+1];
    for(int i = 0; i < n; i++)cin >> a[i];

    for(int i = 0; i < n; i++)
    {
        int b;
        cin >> b;
        if(b == 1)
            d1.pb(a[i]);
        else d2.pb(a[i]);
    }
    sort(d1.rbegin(), d1.rend());
    sort(d2.rbegin(), d2.rend());

    int ans = INT_MAX, si = (int)d2.size();
    ll suma = 0, sumb = accumulate(d2.begin(), d2.end(), 0LL);
    for(int i = 0; i <= d1.size(); i++)
    {
        while(si > 0 && suma + sumb - d2[si-1] >= m)
        {
            si--;
            sumb -= d2[si];
        }
        if(suma + sumb >= m){
            ans = min(ans, 2*si + i);
        }
        if(i != d1.size())
            suma += d1[i];
    }
    if(ans == INT_MAX)cout << "-1" << endl;
    else cout << ans << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
        //tc++;
    }
}
