#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    int T;
    cin >> T;

    while(T--)
    {
        int n, m;
        scanf("%d%d", &n, &m);

        vector <int> a(n);
        for(int& x : a) scanf("%d", &x);

        vector <vector<int>> A(2);
        for(int i = 0; i < n; i++)
        {
            int b;
            scanf("%d", &b);
            A[b - 1].push_back(a[i]);
        }

        for(int b = 0; b < 2; b++)
            sort(A[b].rbegin(), A[b].rend());

        vector <vector <ll>> prefix(2);
        for(int b = 0; b < 2; b++)
            prefix[b].assign(A[b].size() + 1, 0);

        for(int b = 0; b < 2; b++)
            for(int i = 0; i < A[b].size(); i++)
                prefix[b][i + 1] = prefix[b][i] + A[b][i];

        if(prefix[0][A[0].size()] + prefix[1][A[1].size()] < m)
        {
            puts("-1");
            continue;
        }

        int answer = A[0].size() + 2 * A[1].size();
        for(int cnt0 = A[0].size(), cnt1 = 0; cnt0 >= 0; cnt0--)
        {
            while(cnt1 <= A[1].size() && prefix[0][cnt0] + prefix[1][cnt1] < m)
                cnt1++;

            if(cnt1 <= A[1].size())
                answer = min(answer, cnt0 + 2 * cnt1);
        }

        printf("%d\n", answer);
    }
}
