#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define pb push_back
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
#define FOR(i, a, b) for (ll i=a; i < b; i++)

void solve();

int main() {
    ull t;
    cin >> t;
    while(t--) {
        solve();
    }
}

void solve() {
    ll n, m;
    cin >> n >> m;
    vector<ll> nums(n);
    for (auto &x : nums) {
        cin >> x;
    }
    vll p1;
    vll p2;
    for (auto &x : nums) {
        ll is;
        cin >> is;
        if (is == 2) {
            p2.push_back(x);
        } else {
            p1.push_back(x);
        }
    }
    p1.push_back(0); // for safe
    p1.push_back(0); // for safe

    p2.push_back(0); // for safe

    sort(p1.begin(), p1.end(), greater<ll>());
    sort(p2.begin(), p2.end(), greater<ll>());
    ll it1 = 0, it2 = 0;
    ll ans = 0;
    ll cnt = 0;
    FOR(_, 0, n) {
        ll sum = p1[it1] + p1[it1+1];
        if (sum >= p2[it2] || p1[it1] + cnt >= m) {
            cnt += p1[it1];
            it1 += 1;
            ans += 1;
        } else {
            cnt += p2[it2];
            it2 += 1;
            ans += 2;
        }
         if (cnt >= m) {
            break;
        }
         if (_ == n-1) {
             ans = -1; // didnt find
         }
    }
    cout << ans << endl;
    

}