#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, T, a, b;
    cin >> n >> T >> a >> b;
    vector<long long> is_easy(n);
    for (auto &x : is_easy) {
      cin >> x;
      x ^= 1;
    }
    map<long long, pair<long long, long long> > problems;
    long long total_num_easy = 0;
    long long total_num_hard = 0;
    for (long long i = 0; i < n; i++) {
      long long inp;
      cin >> inp;
      if (is_easy[i]) {
        problems[inp].first++;
        total_num_easy++;
      } else {
        problems[inp].second++;
        total_num_hard++;
      }
    }
    long long ans = 0;
    long long num_easy = 0;
    long long num_hard = 0;
    for (auto it = problems.begin(); it != problems.end(); it++) {
      if ((*it).first != 0) {
        long long time = (*it).first - 1;
        long long sub_ans = min(num_easy, time / a);
        time -= min(num_easy, time / a) * a;
        sub_ans += min(num_hard, time / b);
        time -= min(num_hard, time / b) * b;
        if (sub_ans == num_easy + num_hard) {
          sub_ans += min(total_num_easy - num_easy, time / a);
          time -= min(total_num_easy - num_easy, time / a) * a;
          sub_ans += min(total_num_hard - num_hard, time / b);
          ans = max(ans, sub_ans);
        }
      }
      num_easy += (*it).second.first;
      num_hard += (*it).second.second;
    }
    long long time = T;
    long long sub_ans = min(num_easy, time / a);
    time -= min(num_easy, time / a) * a;
    sub_ans += min(num_hard, time / b);
    if (sub_ans == n) ans = sub_ans;
    cout << ans << endl;
  }
}
