#include <bits/stdc++.h>
using namespace std;
int main() {
  int cntTest;
  cin >> cntTest;
  for (int test = 0; test < cntTest; 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 = cnt1 * a + cnt2 * b;
      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);
      }
      if (v[i].second) {
        cnt2++;
      } else {
        cnt1++;
      }
    }
    cout << ans << "\n";
  }
}
