#include <bits/stdc++.h>
using namespace std;
long long nCr(long long n, long long r) {
  vector<vector<long long> > ans(n + 1);
  ans[0].push_back(1);
  ans[1].push_back(1);
  ans[1].push_back(1);
  for (int i = 2; i <= n; i++) {
    ans[i].push_back(1);
    for (int j = 1; j < ans[i - 1].size(); j++) {
      ans[i].push_back(ans[i - 1][j - 1] + ans[i - 1][j]);
    }
    ans[i].push_back(1);
  }
  return ans[n][r];
}
long long lower(vector<pair<long long, long long> > v, long long m) {
  long long l = 1;
  long long r = v.size();
  long long ans;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (v[mid - 1].first == m) {
      return mid - 1;
    } else if (v[mid - 1].first < m) {
      ans = mid;
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  return ans - 1;
}
bool isprime(long long a) {
  for (long long i = 2; i <= sqrt(a); i++) {
    if (a % i == 0) {
      return true;
    }
  }
  return false;
}
long long nmod(long long h, long long m) {
  while (h < 0) {
    h += m;
  }
  return h;
}
int make(string second, string p) {
  transform(second.begin(), second.end(), second.begin(), ::tolower);
  map<char, int> m, k;
  int ans = 0;
  for (int i = 0; i < second.size(); i++) m[second[i]] = 1;
  for (int i = 0; i < p.size(); i++) {
    k[p[i]] = 1;
  }
  for (map<char, int>::iterator it = k.begin(); it != k.end(); it++) {
    if (it->second == m[it->first]) ans++;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  long long t;
  cin >> t;
  while (t--) {
    long long n, T, a, b;
    cin >> n >> T >> a >> b;
    vector<pair<long long, long long> > kk(n);
    for (int i = 0; i < n; i++) {
      cin >> kk[i].second;
    }
    for (int i = 0; i < n; i++) {
      cin >> kk[i].first;
    }
    sort(kk.begin(), kk.end());
    vector<long long> second(n);
    second[n - 1] = kk[n - 1].second;
    for (int i = n - 2; i >= 0; i--) {
      second[i] = second[i + 1] + kk[i].second;
    }
    long long c1 = 0;
    long long c2 = 0;
    long long an = 0;
    for (int i = 0; i < n; i++) {
      long long t = kk[i].first - 1;
      if (t > T) break;
      long long e = a * c1 + b * c2;
      if (e <= t) {
        long long r = t - e;
        long long u = c1 + c2;
        long long w = min(r / a, n - i - second[i]);
        u += w;
        r -= a * w;
        w = min(r / b, second[i]);
        u += w;
        an = max(an, u);
      }
      if (kk[i].second == 1) {
        c2++;
      } else {
        c1++;
      }
    }
    long long d = a * c1 + b * c2;
    if (d <= T) {
      cout << c1 + c2 << endl;
    } else
      cout << an << endl;
  }
}
