#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const long long N = 1e9;
long long binexp(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
void task(bool flag) {
  if (flag)
    cout << "YES\n";
  else
    cout << "NO\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T = 0;
  cin >> T;
  while (T--) {
    long long n, t, a, b;
    cin >> n >> t >> a >> b;
    vector<pair<long long, long long>> ti(n);
    for (long long i = 0; i < (n); ++i) cin >> ti[i].second;
    for (long long i = 0; i < (n); ++i) cin >> ti[i].first;
    sort(ti.begin(), ti.end());
    vector<pair<long long, long long>> hardeasy(n, {0, 0});
    long long hard = 0, easy = 0;
    for (long long i = 0; i < (n); ++i) {
      if (ti[i].second == 1)
        hardeasy[i].first = 1, ++hard;
      else
        hardeasy[i].second = 1, ++easy;
    }
    for (long long i = (1); i <= (n - 1); ++i) {
      hardeasy[i].first += hardeasy[i - 1].first;
      hardeasy[i].second += hardeasy[i - 1].second;
    }
    long long ans = 0;
    long long time = ti[0].first - 1;
    long long score =
        (time / a >= easy) ? easy + min((time - easy * a) / b, hard) : time / a;
    ans = max(ans, score);
    for (long long i = (1); i <= (n - 1); ++i) {
      time = ti[i].first - 1;
      if (hardeasy[i - 1].second * a + hardeasy[i - 1].first * b <= time) {
        score = hardeasy[i - 1].first + hardeasy[i - 1].second;
        time -= hardeasy[i - 1].second * a + hardeasy[i - 1].first * b;
        score += (time / a >= easy - hardeasy[i - 1].second)
                     ? easy - hardeasy[i - 1].second +
                           min((time - (easy - hardeasy[i - 1].second) * a) / b,
                               hard - hardeasy[i - 1].first)
                     : time / a;
      } else {
        score = 0;
      }
      ans = max(ans, score);
    }
    if (hard * b + easy * a <= t) ans = max(ans, n);
    cout << ans << "\n";
  }
  return 0;
}
