#include <bits/stdc++.h>
using namespace std;
vector<int64_t> natural_ans;
void solve() {
  int64_t n, t, a, b;
  cin >> n >> t >> a >> b;
  int64_t HT = 0, LT = 0;
  vector<pair<int64_t, bool>> T(n);
  for (int64_t i = 0; i < n; i++) {
    cin >> T[i].second;
    if (T[i].second) {
      HT++;
    } else {
      LT++;
    }
  }
  for (int64_t i = 0; i < n; i++) {
    cin >> T[i].first;
  }
  T.push_back({t + 1, 0});
  sort(T.begin(), T.end());
  int64_t H = 0, L = 0;
  int64_t ans = 0;
  for (int64_t i = 0; i <= n; i++) {
    int64_t tc = L * a + H * b;
    int64_t priority = T[i].first - tc - 1;
    if (priority >= 0) {
      int64_t ansa = min(LT - L, priority / a);
      priority -= ansa * a;
      int64_t ansb = min(HT - H, priority / b);
      priority -= ansb * b;
      ans = max(ans, ansa + H + L + ansb);
    }
    int64_t j;
    for (j = i; j < T.size() && T[j].first == T[i].first; j++) {
      if (T[j].second) {
        H++;
      } else {
        L++;
      }
    }
    i = j - 1;
  }
  natural_ans.push_back(ans);
}
int32_t main() {
  int64_t q;
  cin >> q;
  while (q--) {
    solve();
  }
  for (int64_t i = 0; i < natural_ans.size(); i++) {
    cout << natural_ans[i] << endl;
  }
}
