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

#define ll long long
#define vi vector<int>
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()

#define pii pair<int, int>
#define mp make_pair
#define f first
#define s second

#define mii map<int, int>
#define umii unordered_map<int, int>
#define li list<int>
#define MOD 1000000007

#define loop(i,s,n) for(int i=s; i<n; i++)

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	
	#ifdef nkTy
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Code ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
	int t; cin >> t;
	int n, m, x, cnt1, cnt2, ans;
	vi arr1(2e5), arr2(2e5);
	ll sum1, sum2;

	while (t--) {
		cin >> n >> m;
		cnt1 = 0; cnt2 = 0;

		loop(i,0,n) cin >> arr1[i];
		loop(i,0,n) {
			cin >> x;
			if (x == 2) {
				arr2[cnt2] = arr1[i];
				cnt2 += 1;
			} else {
				arr1[cnt1] = arr1[i];
				cnt1 += 1;
			}
		}
		sort(arr1.begin(), arr1.begin()+cnt1);
		sort(arr2.begin(), arr2.begin()+cnt2);

		sum1 = 0; sum2 = 0;
		loop(i,0,cnt2) sum2 += arr2[i];
		ans = INT_MAX;

		/*
		5 3 2 1 4	--->	2 3 4 ; 1 5
		2 1 1 2 1	--->	1 1 1 ; 2 2
		*/

		int j=cnt1, k=0;
		while (1) {
			while (k<cnt2 && sum1+sum2-arr2[k] >= m) {
				sum2 -= arr2[k];
				k++;
			}

			if (sum1+sum2 >= m) ans = min(ans, 2*(cnt2-k)+(cnt1-j));

			if (j<=0) break;
			else {
				j--;
				sum1 += arr1[j];
			}
		}

		if (ans == INT_MAX) ans = -1;
		cout << ans << endl;
	}

	return 0;
}

/*
	2
   -1
	6
	4
	3
	3
*/
