// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define minpq priority_queue <int, vector<int>, greater<int> >
using db = long double;
using pll = pair < ll, ll >;
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define hell 1000000007
#define infl LLONG_MAX
#define countBits(n)	__builtin_popcount(n)
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

	ll t, i, x, j, y, z, k, n;
	tc(tt) {
		cin >> n >> k;
		vector<pll> a(n);
		ll org = 0, ans = infl;
		for (auto &zx : a)	cin >> zx.first;
		for (auto &zx : a)	cin >> zx.second;

		std::vector<ll> v1, v2;
		for (auto &[zx, y] : a) {
			if (y == 1)	v1.push_back(zx);
			else v2.push_back(zx);
			org += y;
		}

		if (v2.size() > 0) {
			sort(all(v2));		reverse(all(v2));
		}
		if (v1.size() > 0) {
			sort(all(v1));		reverse(all(v1));
		}

		ll pre = 0;
		for (ll i = 0; i < v1.size(); i++)	pre += v1[i], v1[i] = pre;
		pre = 0;
		for (ll i = 0; i < v2.size(); i++)	pre += v2[i], v2[i] = pre;
		debug(k, v1, v2);

		for (ll i = 0; i < v1.size(); i++) {
			x = v1[i];
			if (x >= k) {
				ans = min(ans, i + 1);
			} else {
				y = i + 1;
				j = lower_bound(all(v2), k - x) - v2.begin();
				y += 2 * (j + 1);
				if (j != v2.size())	ans = min(ans, y);
			}
		}

		for (ll i = 0; i < v2.size(); i++) {
			x = v2[i];
			if (x >= k) {
				ans = min(ans, 2 * i + 2);
			} else {
				y = 2 * i + 2;
				j = lower_bound(all(v1), k - x) - v1.begin();
				y += (j + 1);
				if (j != v1.size())	ans = min(ans, y);
			}
		}

		if (v2.size() > 0 and v2.back() >= k)	ans = min(ans, (ll)(2 * int(v2.size())));
		if (v1.size() > 0 and v1.back() >= k)	ans = min(ans, (ll)(int(v1.size())));

		if (ans == infl)	ans = -1;
		cout << ans << "\n";
		debug(ans);
	}
}

