#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353LL;
long long int n, t, a, b, cnta, cntb;
vector<pair<long long int, long long int> > v;
void solve() {
  cin >> n >> t >> a >> b;
  v.clear();
  cnta = 0;
  cntb = 0;
  v.resize(n);
  for (long long int i = 0; i < n; i++) {
    cin >> v[i].second;
    if (v[i].second)
      cntb++;
    else
      cnta++;
  }
  for (long long int i = 0; i < n; i++) cin >> v[i].first;
  v.push_back({t + 1, 0});
  sort(v.begin(), v.end());
  long long int maxi = 0;
  long long int tot = 0;
  for (long long int i = 0; i < n + 1; i++) {
    pair<long long int, long long int> x = v[i];
    long long int temp = 0;
    long long int rem = x.first - 1 - tot;
    if (rem < 0) {
      if (x.second) {
        tot += b;
        cntb--;
      } else {
        tot += a;
        cnta--;
      }
      continue;
    }
    temp += i;
    long long int xa = min(rem / a, cnta);
    rem -= (a * xa);
    long long int xb = min(rem / b, cntb);
    temp += (xa + xb);
    maxi = max(maxi, temp);
    if (x.second) {
      tot += b;
      cntb--;
    } else {
      tot += a;
      cnta--;
    }
  }
  cout << maxi << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  cin >> t;
  for (long long int i = 0; i < t; i++) {
    solve();
  }
}
