#include <bits/stdc++.h>
using namespace std;
int64_t n;
int64_t T;
int64_t a;
int64_t b;
bool is_hard[200000];
pair<int64_t, int64_t> mandatory[200000];
int64_t nb_easy_problems = 0;
int64_t nb_hard_problems = 0;
void read_data(void) {
  nb_easy_problems = 0;
  nb_hard_problems = 0;
  cin >> n;
  cin >> T;
  cin >> a;
  cin >> b;
  for (int64_t i = 0; i < n; i++) {
    int64_t tmp;
    cin >> tmp;
    if (tmp) {
      is_hard[i] = true;
      nb_hard_problems++;
    } else {
      is_hard[i] = false;
      nb_easy_problems++;
    }
  }
  for (int64_t i = 0; i < n; i++) {
    int64_t tmp;
    cin >> tmp;
    mandatory[i] = make_pair(tmp, i);
  }
}
void solve_case(void) {
  sort(mandatory, mandatory + n);
  for (int64_t i = 0; i < n; i++) {
    pair<int64_t, int64_t> p = mandatory[i];
    ;
  }
  int64_t most_problems = 0;
  int64_t prev_time = 0;
  int64_t nb_prev_easy = 0;
  int64_t nb_prev_hard = 0;
  for (int64_t i = 0; i <= n; i++) {
    int64_t mandatory_time;
    if (i == n)
      mandatory_time = T;
    else
      mandatory_time = min(T, mandatory[i].first - 1);
    ;
    if (i > 0) {
      int64_t prev_index = mandatory[i - 1].second;
      if (is_hard[prev_index]) {
        prev_time += b;
        nb_prev_hard++;
      } else {
        prev_time += a;
        nb_prev_easy++;
      }
    }
    if (prev_time <= (mandatory_time)) {
      int64_t nb_easy = min(nb_easy_problems - nb_prev_easy,
                            (mandatory_time - prev_time) / a);
      int64_t prev_time2 = prev_time + nb_easy * a;
      int64_t nb_hard = 0;
      if (prev_time2 < (mandatory_time))
        nb_hard = min(nb_hard_problems - nb_prev_hard,
                      (mandatory_time - (prev_time2)) / b);
      int64_t solved_problems = i + nb_easy + nb_hard;
      if (most_problems < solved_problems) most_problems = solved_problems;
      ;
      ;
    }
  }
  cout << most_problems << endl;
}
void solve(void) {
  int64_t t;
  cin >> t;
  for (int64_t i = 0; i < t; i++) {
    read_data();
    solve_case();
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
