#include <bits/stdc++.h>
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
std::pair<int, int> operator+(std::pair<int, int> a, std::pair<int, int> b) {
  return {a.first + b.first, a.second + b.second};
}
std::pair<long long, long long> operator+(std::pair<long long, long long> a,
                                          std::pair<long long, long long> b) {
  return {a.first + b.first, a.second + b.second};
}
std::ostream& operator<<(std::ostream& out, std::pair<int, int> a) {
  out << a.first << " " << a.second << "\n";
  return out;
}
std::ostream& operator<<(std::ostream& out, std::pair<long long, long long> a) {
  out << a.first << " " << a.second << "\n";
  return out;
}
std::istream& operator>>(std::istream& in, std::pair<int, int>& a) {
  in >> a.first >> a.second;
  return in;
}
std::istream& operator>>(std::istream& in, std::pair<long long, long long>& a) {
  in >> a.first >> a.second;
  return in;
}
long long bpow(long long x, long long v) {
  if (v == 0) return 1 % 1000000007;
  if (v % 2 == 1) return (x * bpow(x, v - 1)) % 1000000007;
  long long r = bpow(x, v / 2);
  return (r * r) % 1000000007;
}
using namespace std;
void solve() {
  long long n, a, b, ca = 0, cb = 0;
  long long T;
  cin >> n >> T >> a >> b;
  pair<long long, long long> p[n + 1];
  for (int i = 0; i < n; ++i) {
    cin >> p[i].second;
    if (p[i].second == 1)
      cb++;
    else
      ca++;
  }
  for (int i = 0; i < n; ++i) {
    cin >> p[i].first;
  }
  p[n] = {T + 1, 0};
  sort(p, p + n + 1);
  long long ans = 0, a1, ma = 0, mb = 0, time, num, cur;
  for (int i = 0; i <= n; ++i) {
    a1 = 0;
    time = p[i].first - 1;
    time -= ma * a + mb * b;
    if (time >= 0) {
      a1 = ma + mb;
      num = min(time / a, ca - ma);
      time -= num * a;
      a1 += num;
      num = min(time / b, cb - mb);
      time -= num * b;
      a1 += num;
    }
    ans = max(ans, a1);
    cur = i;
    while (cur < n + 1 && p[i].first == p[cur].first) {
      if (cur < n + 1 && p[cur].second == 0)
        ma++;
      else if (cur < n + 1)
        mb++;
      cur++;
    }
    i = cur - 1;
  }
  cout << ans << "\n";
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
