#include <bits/stdc++.h>
using namespace std;
signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long TESTS = 1;
  cin >> TESTS;
  while (TESTS--) {
    long long n, T, a, b;
    cin >> n >> T >> a >> b;
    long long arr[n];
    for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
         i += 1 - 2 * ((0) > (n))) {
      cin >> arr[i];
    }
    long long sum = 0;
    long long time[n];
    vector<long long> easy, hard;
    for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
         i += 1 - 2 * ((0) > (n))) {
      cin >> time[i];
      if (arr[i])
        hard.push_back(time[i]);
      else
        easy.push_back(time[i]);
    }
    sort(time, time + n);
    sort((easy).begin(), (easy).end());
    sort((hard).begin(), (hard).end());
    long long ans = 0;
    for (__typeof(n + 1) i = (0) - ((0) > (n + 1));
         i != (n + 1) - ((0) > (n + 1)); i += 1 - 2 * ((0) > (n + 1))) {
      long long x;
      if (i < n)
        x = time[i] - 1;
      else
        x = T;
      long long pehla =
          upper_bound((easy).begin(), (easy).end(), x) - easy.begin();
      long long dusra =
          upper_bound((hard).begin(), (hard).end(), x) - hard.begin();
      long long y = pehla * a + dusra * b;
      if (y > x) continue;
      y = x - y;
      long long cnt = pehla + dusra;
      long long p = y / a;
      if (p <= (long long)easy.size() - pehla) {
        cnt += p;
      } else {
        y -= a * ((long long)easy.size() - pehla);
        long long q = y / b;
        cnt += min(p, (long long)easy.size() - pehla) +
               min(q, (long long)hard.size() - dusra);
      }
      ans = max(ans, cnt);
    }
    cout << ans << '\n';
  }
}
