#include <bits/stdc++.h>
using namespace std;
inline int64_t max(int64_t a, int64_t b) { return (a > b) ? a : b; }
inline int64_t min(int64_t a, int64_t b) { return (a < b) ? a : b; }
inline int64_t max3(int64_t a, int64_t b, int64_t c) {
  return max(a, max(b, c));
}
inline int64_t min3(int64_t a, int64_t b, int64_t c) {
  return min(a, min(b, c));
}
int64_t gcd(int64_t a, int64_t b) { return (a % b == 0) ? b : gcd(b, a % b); }
int64_t pow3(int64_t a, int64_t b, int64_t m = 1000000007) {
  int64_t res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
void solve() {
  int64_t n, T, a, b;
  cin >> n >> T >> a >> b;
  int64_t x[n];
  for (int64_t i = 0; i < n; i++) cin >> x[i];
  int64_t t[n];
  for (int64_t i = 0; i < n; i++) cin >> t[i];
  pair<int64_t, int64_t> p[n + 1];
  for (int64_t i = 0; i < n; i++) p[i] = make_pair(t[i], x[i]);
  p[n] = make_pair(T + 1, 2);
  sort(p, p + n + 1);
  int64_t ans = 0;
  int64_t pt = 0;
  int64_t sm = 0, hm = 0, sn = 0, hn = 0;
  for (int64_t i = 0; i < n; i++)
    if (x[i] == 1)
      hn++;
    else
      sn++;
  for (int64_t i = 0; i < n + 1; i++) {
    int64_t TT = p[i].first - 1;
    int64_t tans = sm + hm;
    int64_t tt = sm * a + hm * b;
    if (tt <= TT) {
      TT -= tt;
      int64_t exa = min(TT / a, sn);
      tans += exa;
      TT -= exa * a;
      int64_t exb = min(TT / b, hn);
      tans += exb;
      ans = max(ans, tans);
    }
    int64_t l = i;
    while (l < n + 1 && p[l].first == p[i].first) {
      if (p[l].second == 1)
        hm++, hn--;
      else if (p[l].second == 0)
        sm++, sn--;
      l++;
    }
    i = l - 1;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q = 1;
  cin >> q;
  while (q--) {
    solve();
  }
  return 0;
}
