#include <bits/stdc++.h>
using namespace std;
const long long MAX = 2e5 + 9;
const long long INF = 1e12;
vector<pair<long long, long long> > vec;
long long N, T, A, B, res, easy, dif, spent;
long long cal(long long tl, long long ez, long long df) {
  if (tl < 0) return 0;
  if (ez * A > tl) return tl / A;
  tl -= ez * A;
  if (df * B > tl) return ez + tl / B;
  return ez + dif;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    res = 0;
    spent = 0;
    easy = 0;
    dif = 0;
    cin >> N >> T >> A >> B;
    vec.resize(N);
    for (int i = 0; i < N; i++) {
      cin >> vec[i].second;
      if (vec[i].second == 0)
        easy++;
      else
        dif++;
    }
    for (int i = 0; i < N; i++) cin >> vec[i].first;
    sort(vec.begin(), vec.end());
    res = max(res, cal(vec[0].first - 1, easy, dif));
    for (int i = 0; i < N; i++) {
      if (vec[i].second == 0)
        easy--, spent += A;
      else if (vec[i].second == 1)
        dif--, spent += B;
      if (i < N - 1 and spent >= vec[i + 1].first) continue;
      if (i == N - 1 and spent > T) continue;
      if (i == N - 1)
        res = max(res, cal(T - spent - 1, easy, dif) + i + 1);
      else
        res = max(res, cal(vec[i + 1].first - spent - 1, easy, dif) + i + 1);
    }
    cout << res << "\n";
  }
  return 0;
}
