#include <bits/stdc++.h>
using namespace std;
vector<long long int> primes;
void Sieve(long long int n) {
  vector<bool> prime(n + 1, true);
  for (long long int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (long long int p = 2; p <= n; p++)
    if (prime[p]) primes.push_back(p);
}
long long int dnc(long long int bas, long long int power, long long int mod) {
  if (power == 0) return 1;
  if (power % 2 == 0) {
    int res = dnc(bas, power / 2, mod);
    return 1LL * res * res % mod;
  }
  return 1LL * bas * dnc(bas, power - 1, mod) % mod;
}
long long int f[2 * 300010 + 1], inv[2 * 300010 + 1];
void precalc() {
  f[0] = inv[0] = 1;
  for (long long int temp = 1; temp <= 2 * 300010; temp++) {
    f[temp] = 1ll * temp * f[temp - 1] % 10000007;
    inv[temp] = dnc(temp, 10000007 - 2, 10000007) * inv[temp - 1] % 10000007;
  }
}
long long int comb(long long int n, long long int k) {
  if (k > n || k < 0) return 0;
  return f[n] * inv[k] % 10000007 * inv[n - k] % 10000007;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int ti;
    cin >> ti;
    long long int a, b;
    cin >> a;
    cin >> b;
    vector<pair<long long int, long long int>> c(n + 2);
    for (long long int i = 1; i < n + 1; i++) cin >> c[i].second;
    for (long long int i = 1; i < n + 1; i++) cin >> c[i].first;
    c[0].first = 0;
    c[0].second = 0;
    vector<long long int> h(n + 2, 0);
    vector<long long int> e(n + 2, 0);
    c[n + 1] = {ti + 1, 2};
    sort(c.begin() + 1, c.end());
    for (long long int i = 1; i < n + 2; i++) {
      if (c[i].second == 0)
        e[i] = 1;
      else
        h[i] = 1;
      h[i] += h[i - 1];
      e[i] += e[i - 1];
    }
    long long int m = 0;
    long long int ans = 0;
    for (long long int i = 1; i < n + 2; i++) {
      long long int x = h[i - 1];
      long long int y = e[i - 1];
      long long int z = h[n] - h[i - 1];
      long long int w = e[n] - e[i - 1];
      if (c[i].first - 1 >= x * b + y * a) {
        long long int temp = x + y;
        long long int d = c[i].first - 1 - (x * b + y * a);
        temp += min(d / a, w);
        d = d - a * (min((d / a), w));
        temp += min(d / b, z);
        if (c[i].first - 1 <= ti) ans = max(ans, temp);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
