#include<bits/stdc++.h>
using namespace std;
int main()
{
    int tt; cin>>tt;
    while(tt--)
    {
        int n,m; cin>>n>>m;
        vector<int> v(n),a,b;
        for(int i = 0;i<n;i++)
        cin>>v[i];
        for(int i = 0;i<n;i++)
        {
            int t; cin>>t;
            if(t==1)
            a.push_back(v[i]);
            else b.push_back(v[i]);
        }
        sort(a.begin(),a.end(),greater<int>());
        sort(b.begin(),b.end(),greater<int>());
        long long sumA = 0, sumB = accumulate(b.begin(),b.end(),0ll);
        long long r = b.size(), ans = INT_MAX;
        for(int i = 0;i<=a.size();i++)
        {
            while(r>0&&sumB+sumA-b[r-1]>=m)
            r-=1, sumB-=b[r];
            if(sumB+sumA>=m)
            ans = min(ans,2*r+i);
            if(i<a.size())
            sumA += a[i];
        }
        if(ans!=INT_MAX)
        cout<<ans<<endl;
        else cout<<-1<<endl;
    }
}