#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<n;i++)
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define lli long long int
using namespace std;

ostream& operator<<(ostream& os, const vector<int> &v){
    for(auto const &i: v){
        os<<i<<" ";
    }
    os<<endl;
    return os;
}
 int main(){
     int cases;cin>>cases;
     while(cases--){
        int n,m;cin>>n>>m;
        vi  ones,twos; int tmp;
        vi apps;vi pesos;
        int unos= 0,doses = 0;
        long long total = 0;
        REP(i,n){
            cin>>tmp;apps.push_back(tmp);
            total+=tmp;
        }
        REP(i,n){
            cin>>tmp;
            if(tmp==1){ones.push_back(apps[i]);unos++;}
            else {twos.push_back(apps[i]); doses++;}
        }
        sort(twos.rbegin(),twos.rend());sort(ones.rbegin(),ones.rend());
        if(total>=m){
                int i=0; int acum = 0; int ans =0;
                while(i<doses && acum<m){
                        acum+=twos[i];i++;ans+=2;
                }
                if (i>0)i--;
                //int ans2=ans;
                int ans2 = 1e9;
                if(acum>=m) ans2 = min(ans,ans2);
              //  cout<<"Total: "<<acum<<" ans "<<ans<<endl;
                REP(j, unos){
                    acum+=ones[j];
                    ans+=1;
                    //cout<<"Total: "<<acum<<" ans "<<ans<<" ans2  "<<ans2<<endl;
                    while(doses>0 && i>=0 && acum-twos[i]>=m ){
                            acum-=twos[i];ans-=2;
                            i--;
                       // cout<<"SubTotal: "<<acum<<" ans "<<ans<<" ans2  "<<ans<<endl;
                    }
                   if(acum>=m) ans2 = min(ans2,ans);
                }
                //cout<<ans<<endl;
                cout<<ans2<<endl;
        }
        else{
            cout<<-1<<endl;
        }
    }
    return 0;
 }





