#include <bits/stdc++.h>
#define qio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) cerr<<#x<<" "<<x<<endl
#define ll long long 
#define st first
#define nd second
using namespace std;

int n, t, a[200005], b[200005], l, r, res, m;
vector <int> V1, V2;
int main()
{
	qio;
	cin >> t;

	for (int i = 1; i <= t; i++) {
		cin >> n >> m;
		res = 0;
		V1.clear();
		V2.clear();
		for (int j = 1; j <= n; j++) {
			cin >> a[j];
		}

		for (int j = 1; j <= n; j++) {
			cin >> b[j];
		}

		for (int j = 1; j <= n; j++) {
			if (b[j] == 1) V1.push_back(a[j]);
			else V2.push_back(a[j]);
		}

		sort(V1.begin(), V1.end());
		sort(V2.begin(), V2.end());
		l = V1.size() - 1;
		r = V2.size() - 1;
		while (m > 0 && (l != -1 || r != -1)) {
			if (l != -1 && V1[l] >= m) {
				res++;
				m -= V1[l];
				l--;
			}

			else if (l > 0 && r != -1 && V1[l] + V1[l - 1] >= V2[r]) {
				res++;
				m -= V1[l];
				l--;
			}

			else if (l > 0 && r != -1 && V1[l] + V1[l - 1] < V2[r]) {
				res += 2;
				m -= V2[r];
				r--;
			}

			else if (l == 0 && r != -1 && V1[l] >= V2[r]) {
				res++;
				m -= V1[l];
				l--;
			}

			else if (l == 0 && r != -1) {
				res += 2;
				m -= V2[r];
				r--;
			}

			else if (l != -1) {
				res++;
				m -= V1[l];
				l--;
			}
			else {
				res += 2;
				m -= V2[r];
				r--;
			}
		}

		if (m > 0) cout << -1;
		else cout << res;
		cout << endl;

	}


}
