#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define oo (int)(1e17)

int32_t main() {
    cin.sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        int a[n + 1];
        int b[n + 1];
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        vector<int> ones;
        vector<int> twos;
        for (int i = 1; i <= n; i++) {
            cin >> b[i];
            if (b[i] == 1) {
                ones.push_back(a[i]);
            }
            else {
                twos.push_back(a[i]);
            }
        }
        sort(ones.begin(), ones.end());
        sort(twos.begin(), twos.end());
        int pre1[n + 1];
        int pre2[n + 1];
        pre1[0] = 0;
        pre2[0] = 0;
        int aa = (int)(ones.size());
        int bb = (int)(twos.size());
        for (int i = 1; i <= aa; i++) {
            pre1[i] = pre1[i - 1] + ones.back();
            // cout << pre1[i] << " ";
            ones.pop_back();
        }
        for (int i = 1; i <= bb; i++) {
            pre2[i] = pre2[i - 1] + twos.back();
            // cout << pre2[i] << " ";
            twos.pop_back();
        }
        int mn = oo;
        for (int i = 0; i <= aa; i++) {
            auto it = lower_bound(pre2, pre2 + bb + 1, m - pre1[i]);
            if (it != pre2 + bb + 1) {
                mn = min(mn, (ll)(i + 2 * ((int)(it - pre2))));
            }
        }
        if (mn == oo) {
            cout << "-1" << endl;
        }
        else {
            cout << mn << endl;
        }
    }
}