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

#define int long long
#define vi vector<int>
#define fast_io ios_base ::sync_with_stdio(0), cin.tie(0)

signed main()
{
    fast_io;
    int tc;
    cin >> tc;

    while (tc--)
    {
        int n, m, sum = 0;
        cin >> n >> m;

        vi a(n), b(n);
        for (auto &x : a)
        {
            cin >> x;
            sum += x;
        }

        for (auto &x : b)
            cin >> x;

        if (sum < m)
        {
            cout << -1 << '\n';
            continue;
        }

        vi c, d;
        c.push_back(0), d.push_back(0);

        for (int i = 0; i < n; i++)
            if (b[i] == 1)
                c.push_back(a[i]);
            else
                d.push_back(a[i]);

        sort(c.begin() + 1, c.end(), greater<int>());
        sort(d.begin() + 1, d.end(), greater<int>());

        for (int i = 1; i < (int)c.size(); i++)
            c[i] += c[i - 1];

        for (int i = 1; i < (int)d.size(); i++)
            d[i] += d[i - 1];

        int ans = 2 * n;
        for (int i = 0; i < d.size(); i++)
        {
            int req = m - d[i];
            auto it = lower_bound(c.begin(), c.end(), req);

            if (it != c.end())
                ans = min(ans, 2 * i + (it - c.begin()));
        }

        cout << ans << '\n';
    }

    return 0;
}