#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, t, a, b;
  cin >> n >> t >> a >> b;
  vector<int> type(n);
  vector<pair<int, int>> time(n);
  int all = 0;
  for (int i = 0; i < n; ++i) {
    cin >> type[i];
    if (type[i] == 1) ++all;
  }
  for (int i = 0; i < n; ++i) {
    cin >> time[i].first;
    time[i].second = i;
  }
  int ans = 0;
  sort(time.begin(), time.end());
  vector<int> prefsum(n);
  for (int i = 0; i < n; ++i) {
    prefsum[i] = (type[time[i].second] == 1);
    if (i != 0) prefsum[i] += prefsum[i - 1];
  }
  int checktime = time[0].first;
  checktime--;
  if (checktime >= 0) {
    int easy = n - all;
    long long ntime = easy * 1ll * a;
    if (ntime > checktime) {
      ans = max(ans, checktime / a);
    } else {
      checktime -= ntime;
      int curans = easy;
      curans += min(checktime / b, all);
      ans = max(ans, curans);
    }
  }
  for (int i = 0; i < n; ++i) {
    int maxtime = t;
    if (i != n - 1) maxtime = time[i + 1].first - 1;
    int hard = prefsum[i];
    int easy = (i + 1) - hard;
    long long ntime = easy * 1ll * a + hard * 1ll * b;
    if (ntime <= maxtime) {
      maxtime -= ntime;
      int curans = i + 1;
      int hardonsuf = all - prefsum[i];
      int easyonsuf = n - i - 1 - hardonsuf;
      long long needeasy = a * 1ll * easyonsuf;
      if (needeasy > maxtime) {
        curans += maxtime / a;
        ans = max(ans, curans);
      } else {
        curans += easyonsuf;
        maxtime -= needeasy;
        curans += min(maxtime / b, hardonsuf);
        ans = max(ans, curans);
      }
    }
  }
  cout << ans << "\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
