#include <bits/stdc++.h>
using namespace std;
struct node {
  long long typ;
  long long t;
} pro[200100];
long long cmp(node p, node q) { return p.t < q.t; }
signed main() {
  long long _;
  scanf("%lld", &_);
  while (_--) {
    long long easy = 0;
    long long diff = 0;
    long long n, T, a, b;
    scanf("%lld%lld%lld%lld", &n, &T, &a, &b);
    for (long long i = 1; i <= n; i++) {
      scanf("%lld", &pro[i].typ);
      if (pro[i].typ == 0)
        easy++;
      else
        diff++;
    }
    for (long long i = 1; i <= n; i++) {
      scanf("%lld", &pro[i].t);
    }
    sort(pro + 1, pro + 1 + n, cmp);
    long long sum = 0;
    pro[n + 1].t = T + 1;
    long long ans = 0;
    for (long long i = 0; i <= n; i++) {
      if (i != 0) {
        if (pro[i].typ == 0)
          sum += a, easy--;
        else
          sum += b, diff--;
      }
      if ((pro[i].t != pro[i + 1].t || i == n || i == 0) && sum <= T &&
          sum < pro[i + 1].t) {
        long long res = pro[i + 1].t - sum - 1;
        long long num1 = min(res / a, easy);
        res -= num1 * a;
        long long num2 = min(res / b, diff);
        ans = max(ans, i + num1 + num2);
      }
    }
    printf("%lld\n", ans);
  }
}
