#include <bits/stdc++.h>
using namespace std;
long long int po(long long int x, long long int n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return po((x * x) % 1000000007, n / 2);
  else
    return (x * po((x * x) % 1000000007, (n - 1) / 2)) % 1000000007;
}
long long int GCD(long long int A, long long int B) {
  if (B == 0)
    return A;
  else
    return GCD(B, A % B);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, T, a, b;
    cin >> n >> T >> a >> b;
    vector<pair<int, int>> d(n);
    for (int i = 0; i < n; ++i) cin >> d[i].second;
    for (int i = 0; i < n; ++i) cin >> d[i].first;
    long long int su[n];
    sort(d.begin(), d.end());
    su[n - 1] = d[n - 1].second;
    for (int i = n - 2; i >= 0; --i) su[i] = su[i + 1] + d[i].second;
    long long int c1 = 0, c2 = 0;
    long long int an = 0;
    for (int i = 0; i < n; ++i) {
      long long int t = d[i].first - 1;
      if (t > T) break;
      long long int e = a * c1 + b * c2;
      if (e <= t) {
        long long int y = t - e;
        long long int w = c1 + c2;
        long long int u = min(y / a, n - i - su[i]);
        w += u;
        y -= u * a;
        u = min(y / b, su[i]);
        w += u;
        an = max(an, w);
      }
      if (d[i].second == 1)
        c2++;
      else
        c1++;
    }
    long long int d1 = c1 * a + c2 * b;
    if (d1 <= T) an = c1 + c2;
    cout << an << "\n";
  }
}
