#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  long long tc;
  cin >> tc;
  while (tc--) {
    long long n, t, a, b;
    cin >> n >> t >> a >> b;
    vector<long long> di(n);
    for (int i = 0; i < n; i++) cin >> di[i];
    vector<long long> ti(n);
    for (int i = 0; i < n; i++) cin >> ti[i];
    vector<tuple<long long, long long> > p;
    vector<long long> cnt(2);
    for (int i = 0; i < n; i++) {
      p.emplace_back(ti[i], di[i]);
      cnt[di[i]]++;
    }
    sort(begin(p), end(p));
    long long req = 0, ans = 0, sol = 0;
    for (int i = 0; i < n; i++) {
      auto [x, d] = p[i];
      long long aux = x - 1 - req;
      if (aux >= 0) {
        long long na = min(cnt[0], aux / a);
        aux -= na * a;
        long long nb = min(cnt[1], aux / b);
        ans = max(ans, sol + na + nb);
      }
      cnt[d]--;
      req += d == 0 ? a : b;
      sol++;
    }
    if (t >= req) {
      ans = max(ans, sol);
    }
    cout << ans << "\n";
  }
}
