#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using pii = pair<ll, int>;
bool ch[(int)2e5 + 5];
int solve() {
  int n, x, qe = 0;
  ll T, a, b;
  scanf("%d%lld%lld%lld", &n, &T, &a, &b);
  map<int, pii> mp;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    ch[i] = (x == 1);
    if (!ch[i]) qe++;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (!mp.count(x)) {
      mp[x] = make_pair(0LL, 0);
    }
    if (ch[i]) {
      mp[x].first += b;
    } else
      mp[x].first += a, mp[x].second += 1;
  }
  ll tt = 0LL;
  int ma = 0, sum = 0, qez = 0;
  for (auto it : mp) {
    int inv = it.first - tt;
    int val = 0;
    if (inv > 0) {
      val = min(qe - qez, inv / (int)a - (inv % (int)a == 0));
      int q = inv - val * (int)a;
      if (q > 0) val += min(n - qe - sum + qez, q / (int)b - (q % (int)b == 0));
    }
    if (inv > 0) ma = max(ma, sum + val);
    sum += it.second.second +
           (int)((it.second.first - a * (ll)(it.second.second)) / b);
    tt += it.second.first;
    qez += it.second.second;
    if (tt > T) return !printf("%d\n", ma);
  }
  ma = n;
  return !printf("%d\n", ma);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
}
