#include <bits/stdc++.h>
using namespace std;
long long solve() {
  long long n, T, a, b;
  cin >> n >> T >> a >> b;
  vector<long long> hard(n);
  long long x;
  long long hardcount = 0, easycount = 0;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    if (x) {
      hard[i] = b;
      ++hardcount;
    } else {
      hard[i] = a;
      ++easycount;
    }
  }
  vector<long long> mand(n);
  for (int i = 0; i < n; ++i) {
    cin >> mand[i];
  }
  vector<pair<long long, long long>> prob(n);
  for (int i = 0; i < n; ++i) {
    prob[i] = make_pair(mand[i], hard[i]);
  }
  sort(prob.begin(), prob.end());
  int m_easy = 0, m_hard = 0;
  long long res = 0;
  long long musttime = 0;
  for (int i = 0; i < n; ++i) {
    long long time = prob[i].first - musttime;
    if (time > 0) {
      long long solved = m_easy + m_hard;
      --time;
      solved += min(time / a, easycount - m_easy);
      time -= min(time / a, easycount - m_easy) * a;
      solved += min(time / b, hardcount - m_hard);
      time -= min(time / b, hardcount - m_hard) * b;
      res = max(res, solved);
    }
    if (prob[i].second == b) {
      ++m_hard;
      musttime += b;
    } else {
      ++m_easy;
      musttime += a;
    }
  }
  long long time = T - musttime;
  if (time >= 0) res = n;
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(30);
  cout << fixed;
  int t;
  cin >> t;
  while (t--) {
    cout << solve() << endl;
  }
  return 0;
}
