#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  for (int xx = 1; xx <= T; xx++) {
    long long n, t, a, b;
    cin >> n >> t >> a >> b;
    vector<int> dif(n);
    vector<long long> ti(n);
    vector<long long> tt(n);
    map<long long, long long> mpA;
    map<long long, long long> mpB;
    int totalA = 0, totalB = 0;
    for (int i = 0; i < n; ++i) {
      cin >> dif[i];
      if (dif[i])
        totalB++;
      else
        totalA++;
    }
    for (int j = 0; j < n; ++j) {
      cin >> ti[j];
      tt[j] = ti[j];
      if (dif[j])
        mpB[ti[j]] += b;
      else
        mpA[ti[j]] += a;
    }
    sort((ti).begin(), (ti).end());
    ti.push_back(t + 1);
    long long ans = 0;
    long long acumA = 0;
    long long acumB = 0;
    long long cntA = 0;
    long long cntB = 0;
    for (int k = 0; k <= n; ++k) {
      if (k == 0 || ti[k] != ti[k - 1]) {
        long long tim = ti[k] - 1;
        if (tim >= acumA + acumB) {
          long long aux = cntA + cntB;
          tim -= acumA + acumB;
          long long mini = min((totalA - cntA), tim / a);
          aux += mini;
          tim -= mini * a;
          mini = min((totalB - cntB), tim / b);
          aux += mini;
          tim -= mini * b;
          ans = max(aux, ans);
        }
        acumA += mpA[ti[k]];
        acumB += mpB[ti[k]];
        cntA += mpA[ti[k]] / a;
        cntB += mpB[ti[k]] / b;
      }
    }
    cout << ans << "\n";
  }
}
