#include <bits/stdc++.h>
using namespace std;
void prinv(vector<long long> &v) {
  copy(v.begin(), v.end(), ostream_iterator<int>(cout, " "));
  cout << endl;
}
const long long mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int _;
  cin >> _;
  while (_--) {
    long long n, T, a, b;
    cin >> n >> T >> a >> b;
    vector<long long> point = {a, b};
    vector<pair<long long, long long> > v(n);
    int x;
    int total_easy = 0;
    for (int i = 0; i < n; i++) {
      cin >> x;
      v[i].second = point[x];
      total_easy += 1 - x;
    }
    for (int i = 0; i < n; ++i) {
      cin >> v[i].first;
    }
    sort(v.begin(), v.end());
    long long cur_time = 0;
    int solved = 0, final = 0;
    int i = 0;
    while (cur_time < T && i < n) {
      if (cur_time >= v[i].first) {
        cur_time += v[i].second;
        if (v[i].second == a) total_easy--;
        solved++;
        i++;
      } else {
        final = max(final, solved);
        if (v[i].second == b) {
          long long extra_time = v[i].first - cur_time - 1;
          int extra_solve = min(extra_time / a, 1LL * total_easy);
          final = max(final, solved + extra_solve);
        }
        cur_time += v[i].second;
        if (v[i].second == a) total_easy--;
        solved++;
        i++;
      }
    }
    int res = 0;
    if (cur_time <= T && i == n) res = solved;
    cout << max(res, final) << endl;
  }
}
