#include <bits/stdc++.h>
using namespace std;
long long int t[300005];
long long int type[300005];
vector<pair<long long int, long long int> > v;
vector<long long int> res;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T, n, i, j, k, m, a, b, l, q;
  cin >> q;
  while (q--) {
    cin >> n >> T >> a >> b;
    for (i = 1; i <= n; i++) cin >> type[i];
    for (i = 1; i <= n; i++) {
      cin >> t[i];
      v.push_back({t[i], i});
    }
    sort(v.begin(), v.end());
    long long int easy = 0;
    for (i = 1; i <= n; i++) {
      if (type[i] == 0) easy++;
    }
    long long int sum = 0;
    for (i = 0; i < n; i++) {
      if (type[v[i].second] == 0)
        sum += a;
      else
        sum += b;
      res.push_back(sum);
    }
    long long int maxi = min((max(v[0].first - 1, 0LL)) / a, easy);
    long long int cnt = 0;
    for (i = 0; i < n - 1; i++) {
      if (type[v[i].second] == 0) easy--;
      if (v[i + 1].first > res[i]) {
        maxi = max(i + 1 + min((v[i + 1].first - 1 - res[i]) / a, easy), maxi);
      }
    }
    if (res[n - 1] <= T) maxi = n;
    cout << maxi << endl;
    res.clear();
    v.clear();
  }
  return 0;
}
