#include <bits/stdc++.h>
using namespace std;
struct problem {
  long long t;
  int har;
} prob[200005];
bool msf(problem a, problem b) { return a.t < b.t; }
long long q, n, T, a, b, har, t;
long long ans, sol, curt, tel, curh, cure;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> q;
  while (q--) {
    cin >> n >> T >> a >> b;
    ans = 0;
    curt = 0;
    cure = 0;
    curh = 0;
    tel = 0;
    for (int i = 1; i <= n; i++) {
      cin >> har;
      prob[i].har = har;
      if (har == 0)
        cure++;
      else
        curh++;
    }
    for (int i = 1; i <= n; i++) {
      cin >> t;
      prob[i].t = t;
    }
    sort(prob + 1, prob + n + 1, msf);
    if (cure * a + curh * b <= T) {
      cout << n << endl;
      continue;
    }
    for (int i = 1; i <= n; i++) {
      curt = prob[i].t - 1;
      if (prob[i].t != prob[i - 1].t) {
        sol = i - 1;
        sol += min((curt - tel) / a, cure);
        sol += max(0LL, (curt - tel - a * cure) / b);
        if (curt >= tel) ans = max(ans, sol);
      }
      if (prob[i].har) {
        tel += b;
        curh--;
      } else {
        tel += a;
        cure--;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
