#include <bits/stdc++.h>
using namespace std;
bool comp(const pair<long long, long long>& a,
          const pair<long long, long long>& b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first < b.first;
}
int main() {
  long long i, j, k;
  long long t;
  cin >> t;
  while (t--) {
    long long n, T, a, b;
    cin >> n >> T >> a >> b;
    long long ac = 0, bc = 0;
    vector<pair<long long, long long> > v(n);
    for (i = (0); i < (n); i++) {
      cin >> v[i].second;
      if (v[i].second == 0)
        ac++;
      else
        bc++;
    }
    vector<bool> skip(n, false);
    for (i = (0); i < (n); i++) cin >> v[i].first;
    sort((v).begin(), (v).end(), comp);
    for (i = (0); i < (n - 1); i++) {
      if (v[i].first == v[i + 1].first) skip[i] = true;
    }
    long long ans = 0, csum = 0;
    for (i = (0); i < (n); i++) {
      long long base = i;
      long long diff = (v[i].first - csum - 1);
      if (diff >= 0 && ((i == 0) || (v[i - 1].first != v[i].first))) {
        long long aac = min(ac, diff / a);
        base += aac;
        diff -= aac * a;
        base += min(bc, diff / b);
        ans = max(ans, base);
      }
      csum += ((v[i].second == 0) ? a : b);
      if (v[i].second == 0)
        ac--;
      else
        bc--;
    }
    if (T >= csum) ans = n;
    cout << ans << '\n';
  }
  return 0;
}
