#include <bits/stdc++.h>
using namespace std;
long long tipo[200001];
pair<long long, long long> val[200001];
signed main() {
  long long M, N, T, a, b, x;
  scanf("%lld", &M);
  while (M--) {
    scanf("%lld %lld %lld %lld", &N, &T, &a, &b);
    long long acum1 = 0, acum2 = 0;
    for (long long i = 0; i < N; i++) {
      scanf("%lld", &x);
      tipo[i] = x;
      acum1 += x == 0;
      acum2 += x == 1;
    }
    for (long long i = 0; i < N; i++) {
      scanf("%lld", &x);
      val[i] = {x, tipo[i]};
    }
    if (acum1 * a + acum2 * b <= T) {
      printf("%lld\n", N);
      continue;
    }
    sort(val, val + N);
    long long ptr = 0;
    long long ma = 0, A = 0, B = 0;
    long long obrigatorio = 0;
    while (ptr < N) {
      if (val[ptr].first != 0) {
        long long y = val[ptr].first - 1;
        long long k = 0;
        if (y >= obrigatorio) {
          y -= obrigatorio;
          long long v = y / a;
          k += min(v, acum1 - A);
          y -= min(v, acum1 - A) * a;
          v = y / b;
          k += min(v, acum2 - B);
          y -= min(v, acum2 - B) * b;
          ma = max(ma, A + B + k);
        }
      }
      long long i;
      for (i = ptr; i < N; i++) {
        if (val[i].first != val[ptr].first) break;
        if (val[i].second == 0) {
          obrigatorio += a;
          A++;
        } else {
          obrigatorio += b;
          B++;
        }
      }
      ptr = i;
    }
    printf("%lld\n", ma);
  }
  return 0;
}
