#include <bits/stdc++.h>
using namespace std;
int get(long long X, int easy, int hard, int a, int b) {
  long long res = 0;
  if (a < b) {
    long long can = min(1LL * easy, X / a);
    res += can;
    X -= 1LL * can * a;
    can = min(1LL * hard, (X / b));
    res += can;
  } else {
    long long can = min(1LL * hard, X / b);
    res += can;
    X -= 1LL * can * b;
    can = min(1LL * easy, X / a);
    res += can;
  }
  return (int)res;
}
void solve() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, T, a, b;
    cin >> n >> T >> a >> b;
    vector<int> d(n, 0);
    for (int i = 0; i < n; ++i) cin >> d[i];
    vector<int> t(n, 0);
    for (int i = 0; i < n; ++i) cin >> t[i];
    vector<pair<int, int>> v(n);
    int easy = 0, hard = 0;
    for (int i = 0; i < n; ++i) {
      v[i] = make_pair(t[i], d[i]);
      if (d[i])
        hard++;
      else
        easy++;
    }
    sort(v.begin(), v.end());
    int ans = 0;
    int x = 0, y = 0;
    for (int i = 0; i < n; ++i) {
      long long X = v[i].first - 1;
      if (X >= 0 && X >= (1LL * x * a + 1LL * y * b)) {
        ans = max(ans, x + y +
                           get(X - (1LL * x * a + 1LL * y * b), easy - x,
                               hard - y, a, b));
      }
      int j = i;
      int curx = x, cury = y;
      while (j < n && v[j].first == v[i].first) {
        if (v[j].second)
          cury++;
        else
          curx++;
        j++;
      }
      if (v[i].first >= (1LL * curx * a + 1LL * cury * b)) {
        ans = max(ans, curx + cury +
                           get(v[i].first - (1LL * curx * a + 1LL * cury * b),
                               easy - curx, hard - cury, a, b));
      }
      x = curx, y = cury;
      i = j - 1;
    }
    if (T >= (1LL * x * a + 1LL * y * b)) {
      ans = max(ans, x + y +
                         get(T - (1LL * x * a + 1LL * y * b), easy - x,
                             hard - y, a, b));
    }
    cout << ans << '\n';
  }
}
int main() {
  solve();
  return 0;
}
