#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, T, a, b;
  cin >> n >> T >> a >> b;
  long long int hcnt = 0, ecnt = 0;
  vector<bool> hard(n + 1, 0);
  for (long long int i = 1; i <= n; i++) {
    long long int g;
    cin >> g;
    hard[i] = g;
    if (hard[i] == 1)
      hcnt++;
    else
      ecnt++;
  }
  vector<pair<long long int, long long int> > vp(n + 1);
  vp[0] = {-1, -1};
  for (long long int i = 1; i <= n; i++) {
    long long int g;
    cin >> g;
    vp[i] = {g, i};
  }
  sort(vp.begin(), vp.end());
  long long int ans = 0;
  long long int t_hard = hcnt, t_easy = ecnt;
  if (t_hard + t_easy != n) {
    cout << "********FATAL ERROR********** \n\n\n";
  }
  for (long long int i = 0; i <= n; i++) {
    long long int maxi = 0;
    if (i != 0 && hard[vp[i].second] && i != 0)
      hcnt--;
    else if (i != 0)
      ecnt--;
    if (i + 1 <= n && vp[i + 1].first == vp[i].first) {
      continue;
    } else {
      long long int cur_time;
      if (i + 1 <= n)
        cur_time = min(vp[i + 1].first - 1, T);
      else
        cur_time = T;
      long long int time_passed = (t_hard - hcnt) * b + (t_easy - ecnt) * a;
      long long int time_remain = cur_time - time_passed;
      if (time_remain >= 0) {
        maxi = min(time_remain / a, ecnt);
        time_remain = time_remain - maxi * a;
        maxi += min(hcnt, time_remain / b);
        maxi += i;
      }
      ans = max(ans, maxi);
    }
  }
  cout << ans << endl;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
