#include <cstring>
#include <iostream>
#include<algorithm>
#include<climits>
using namespace std;
struct application
{
	long long a;
	long long b;
}app[200010];
long long app_a[200010], app_b[200010];
bool cmp(long long a, long long b)
{
	if (a > b)
		return true;
	else
		return false;
}
void solve()
{
	long long n, m;
	cin >> n >> m;
	long long t_a, t_b;
	long long sum_a, sum_b=0;
	t_a = 0;
	t_b = 0;
	for (int i = 0; i < n; i++)
		cin >> app[i].a;
	for (int i = 0; i < n; i++)
	{
		cin >> app[i].b;
		if (app[i].b == 1)
			app_a[t_a++] = app[i].a;
		else
		{
			app_b[t_b++] = app[i].a;
			sum_b += app[i].a;
		}
	}
	sort(app_a, app_a + t_a,cmp);
	sort(app_b, app_b + t_b,cmp);
	sum_a = 0;
	long long ans = INT_MAX;
	for (int i = 0; i <= t_a; i++)
	{
		while (t_b > 0 && sum_a + sum_b - app_b[t_b - 1] >= m)
		{
			t_b--;
			sum_b -= app_b[t_b];
		}
		if (sum_a + sum_b >= m)
		{
			ans = min(ans, i + 2 * t_b);
		}
		if (i != t_a)
			sum_a += app_a[i];
	}
	if (ans == INT_MAX)
		cout << "-1" << "\n";
	else
		cout << ans << "\n";
}
int main()
{

	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}