//
//  main.cpp
//
//
//  Created by ji luyang on 2020/12/22.
//

#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <time.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
int t;
int n, m;
int a[200010], b[200010];
int main() {
    cin >> t;
    while (t--) {
        cin >> n >> m;
        vector<int> v1, v2;
        long long s1 = 0, s2 = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        for (int i = 0; i < n; i++) {
            scanf("%d", &b[i]);
        }
        for (int i = 0; i < n; i++) {
            if (b[i] == 1) v1.push_back(a[i]), s1 += a[i];
            else v2.push_back(a[i]), s2 += a[i];
        }
        sort(v1.begin(), v1.end(), greater<int>());
        sort(v2.begin(), v2.end(), greater<int>());
        int p2 = v2.size() - 1, p1 = -1, res = INT_MAX;
        if (s1 + s2 < m) {
            printf("-1\n");
            continue;
        }
        long long tmp = s2;
        while (p2 >= -1) {
            while (tmp < m) {
                p1++;
                if (p1 == v1.size()) break;
                tmp += v1[p1];
            }
            if (p1 == v1.size()) break;
            res = min(res, p1 + 1 + 2 * (p2 + 1));
            if (p2 == -1) break;
            tmp -= v2[p2];
            p2--;
        }
        printf("%d\n", res);
    }
    return 0;
}

