# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
#define pii pair<int,int>
const int N = 2e5 + 5;
const int INF = 1e9;
const ll mod = 1e9+7;
ll n,m,arr[N],b[N];
vector<ll>v,v2;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(,r,stdin);
    //freopen(,w,stdout);
    int t;
    cin>>t;
    while(t--){
        bool g = 0;
        cin>>n>>m;
        for(int i =1 ;i<=n;i++){
            cin>>arr[i];
        }
        for(int i =1 ;i<=n;i++){
            int kode;
            cin>>kode;
            if(kode == 1) v.pb(arr[i]);
            else v2.pb(arr[i]);
        }

        sort(v.rbegin(),v.rend());
        sort(v2.rbegin(),v2.rend());
        int sz = v.size();
        for(int i = 1;i<sz;i++){
            v[i] = v[i-1] + v[i];
        }
        int sz2 = v2.size();
        for(int i = 1;i<sz2;i++){
            v2[i] = v2[i-1] + v2[i];
        } 
        ll ans = INF;
        auto it = lower_bound(v2.begin(),v2.end(),m);
        if(it != v2.end()) {
            int pos = it - v2.begin() +1;
            ans = 2 * pos;
        }
        for(ll i = 0;i<sz;i++){
            if(v2.size() == 0){
                if(v[i] >= m){
                    ans = min(ans,i+1);
                    break;
                }
            }
            else{
                auto it = lower_bound(v2.begin(),v2.end(),m - v[i]);
                if(it == v2.end()) continue;
                int pos = it - v2.begin() +1;
                if(m-v[i] <=0) pos = 0;
                //cout<<i+1<<" "<<pos<<endl;
                ans = min(ans,i+1 + 2 * pos);

            }
        }
        if(ans == INF) ans = -1;
        cout<<ans<<'\n';
        v.clear();
        v2.clear();
    }
}