#include <bits/stdc++.h>
using namespace std;
pair<int, int> pa[200020];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, t, a, b;
    long long int cntA = 0, cntB = 0, ans = 0;
    long long int totA = 0, totB = 0;
    cin >> n >> t >> a >> b;
    for (int i = 0; i < n; ++i) {
      cin >> pa[i].second;
      if (pa[i].second)
        ++totB;
      else
        ++totA;
    }
    for (int i = 0; i < n; ++i) cin >> pa[i].first;
    sort(pa, pa + n);
    for (int i = 0; i <= n;) {
      long long int need = cntA * (long long int)a + cntB * (long long int)b;
      long long int res;
      if (i < n)
        res = pa[i].first - 1 - need;
      else
        res = t - need;
      long long int solA = 0, solB = 0;
      if (res > 0) {
        solA = min(totA - cntA, res / a);
        res -= solA * a;
      }
      if (res > 0) {
        solB = min(totB - cntB, res / b);
        res -= solB * b;
      }
      if (res >= 0) {
        ans = max(ans, cntA + cntB + solA + solB);
      }
      if (i == n) break;
      int j;
      for (j = i; j < n && pa[j].first == pa[i].first; ++j) {
        if (pa[j].second)
          ++cntB;
        else
          ++cntA;
      }
      i = j;
    }
    cout << ans << '\n';
  }
}
