#include <bits/stdc++.h>
#define INF 1001001001
typedef long long ll;
using namespace std;
template <typename T>
void show(vector<T> &a) {
	for (int i = 0; i < a.size(); i++) {
		cout << a[i];
		if (i == a.size() - 1) {
			cout << endl;
		} else {
			cout << " ";
		}
	}
}
template <typename T>
void show(T &a) {
	cout << a << endl;
}

int main() {
	int tt;
	cin >> tt;
	while (tt--) {
		int n, m;
		cin >> n >> m;
		vector<int> a(n);
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		vector<int> b(n);
		for (int i = 0; i < n; i++) {
			cin >> b[i];
		}

		vector<int> v1, v2;
		for (int i = 0; i < n; i++) {
			if (b[i] == 1) {
				v1.push_back(a[i]);
			} else {
				v2.push_back(a[i]);
			}
		}
		sort(v1.begin(), v1.end(), greater<int>());
		sort(v2.begin(), v2.end(), greater<int>());
		int nv1 = v1.size(), nv2 = v2.size();
		vector<ll> sv1(nv1 + 1, 0), sv2(nv2 + 1, 0);
		for (int i = 0; i < nv1; i++) {
			sv1[i + 1] += sv1[i] + v1[i];
		}
		for (int i = 0; i < nv2; i++) {
			sv2[i + 1] += sv2[i] + v2[i];
		}

		// show(sv1);
		// show(sv2);

		int ans = INF;
		for (int i = 0; i <= nv1; i++) {
			ll tot = sv1[i];
			ll left = m - tot;
			if (left > sv2[nv2]) continue;
			int ok = nv2, ng = -1, mid;
			while (abs(ok - ng) > 1) {
				mid = (ok + ng) / 2;
				if (left <= sv2[mid]) {
					ok = mid;
				} else {
					ng = mid;
				}
			}
			// show(i);
			// show(ok);
			ans = min(ans, i + ok * 2);
		}
		if (ans == INF) ans = -1;
		cout << ans << endl;
	}
	return 0;
}