#include <bits/stdc++.h>
using namespace std;
int tt[2 * 100005];
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
struct node {
  int ac = 0, bc = 0, tot = 0, ct = 0;
};
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    map<long long, node> mm;
    long long n, T, a, b, i, x, ans = 0, val = 0, val1 = 0;
    long long a_rem = 0, b_rem = 0;
    scanf("%lld", &n);
    scanf("%lld", &T);
    scanf("%lld", &a);
    scanf("%lld", &b);
    for (i = 0; i < n; i++) scanf("%d", &tt[i]);
    for (i = 0; i < n; i++) {
      scanf("%lld", &x);
      if (tt[i]) {
        mm[x].bc++;
        mm[x].tot += b;
        b_rem++;
      } else {
        mm[x].ac++;
        mm[x].tot += a;
        a_rem++;
      }
      mm[x - 1].ac += 0;
      mm[x - 1].bc += 0;
      mm[x - 1].tot += 0;
      mm[x - 1].ct += 0;
      mm[x].ct++;
    }
    mm[T].ac += 0;
    mm[T].bc += 0;
    mm[T].tot += 0;
    mm[T].ct += 0;
    for (auto it : mm) {
      a_rem -= it.second.ac;
      b_rem -= it.second.bc;
      val += it.second.ct;
      val1 += it.second.tot;
      ;
      ;
      if (it.first >= val1) {
        long long x = it.first - val1;
        long long y = x / a;
        long long ext = 0;
        x -= (min(y, a_rem) * a);
        ext += min(y, a_rem);
        y = x / b;
        x -= (min(y, b_rem) * b);
        ext += min(y, b_rem);
        ans = max(ans, val + ext);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
