#include <bits/stdc++.h>
using namespace std;
pair<int, int> prob[234567];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int test;
  cin >> test;
  while (test--) {
    int n, t, a, b;
    cin >> n >> t >> a >> b;
    long long hard_cnt = 0, easy_cnt = 0;
    for (int i = 0; i < n; ++i) {
      cin >> prob[i].second;
      if (prob[i].second)
        hard_cnt++;
      else
        easy_cnt++;
    }
    for (int i = 0; i < n; ++i) cin >> prob[i].first;
    sort(prob, prob + n);
    prob[n] = {t + 1, 0};
    long long need_hard = 0, need_easy = 0, res = 0;
    for (int i = 0; i <= n; ++i) {
      long long total_time = prob[i].first - 1;
      total_time -= need_easy * a + need_hard * b;
      long long cnt = 0;
      if (total_time >= 0) {
        cnt = need_hard + need_easy;
        cnt += min(total_time / a, easy_cnt);
        total_time -= min(total_time / a * a, easy_cnt * a);
        cnt += min(total_time / b, hard_cnt);
      }
      res = max(res, cnt);
      if (prob[i].second) {
        need_hard++, hard_cnt--;
      } else {
        need_easy++, easy_cnt--;
      }
    }
    cout << res << endl;
  }
  return 0;
}
