#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
template <typename T>
void print(T v) {
  for (auto i = v.begin(); i != v.end(); i++) cout << setw(2) << *i << " ";
  cout << endl;
}
template <typename T>
void print_vv(T v, bool same_line = true) {
  for (auto i = 0; i < v.size(); i++) {
    cout << "{";
    for (auto j = 0; j != v[i].size(); j++) {
      cout << setw(3) << v[i][j] << ",";
    }
    cout << "},";
    if (same_line) cout << endl;
  }
  cout << endl;
}
int main() {
  int test;
  cin >> test;
  while (test--) {
    long long n, t, a, b;
    cin >> n >> t >> a >> b;
    vector<pair<long long, long long> > v;
    vector<int> hard(n);
    int cntA = 0, cntB = 0;
    for (int i = 0; i < n; i++) {
      cin >> hard[i];
      if (hard[i])
        cntB++;
      else
        cntA++;
    }
    for (int i = 0; i < n; i++) {
      long long time;
      cin >> time;
      v.push_back({time, hard[i]});
    }
    v.push_back({t + 1, 0});
    sort(v.begin(), v.end());
    long long cnt1 = 0, cnt2 = 0;
    long long ans = 0;
    for (int i = 0; i <= n; i++) {
      long long need = a * cnt1 + b * cnt2;
      long long has = v[i].first - 1 - need;
      if (has >= 0) {
        long long canA = min((cntA - cnt1), has / a);
        has -= canA * a;
        long long canB = min((cntB - cnt2), has / b);
        ans = max(ans, cnt1 + cnt2 + canA + canB);
      }
      int l = i;
      if (v[l].second)
        cnt2++;
      else
        cnt1++;
    }
    cout << ans << endl;
  }
  return 0;
}
