#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U>
ostream& operator<<(ostream& o, const pair<T, U>& p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
int solve() {
  int n, t;
  ll x[2];
  scanf(" %d %d %lld %lld", &n, &t, &x[0], &x[1]);
  vector<int> d(n), ct(2);
  for (int i = 0; i < (int)(n); ++i) {
    scanf(" %d", &d[i]);
    ++ct[d[i]];
  }
  vector<int> ut;
  map<int, vector<int>> mandatory;
  for (int i = 0; i < (int)(n); ++i) {
    int a;
    scanf(" %d", &a);
    mandatory[a].push_back(i);
    ut.push_back(a);
    if (a - 1 >= 0) ut.push_back(a - 1);
  }
  ut.push_back(0);
  ut.push_back(t);
  sort((ut).begin(), (ut).end());
  ut.erase(unique((ut).begin(), (ut).end()), ut.end());
  int ans = 0;
  vector<int> must(2);
  for (int i : ut) {
    for (int j : mandatory[i]) ++must[d[j]];
    ll need = 0;
    for (int j = 0; j < (int)(2); ++j) need += x[j] * must[j];
    if (need > i) continue;
    int tmp = must[0] + must[1];
    int rem = i - need;
    for (int j = 0; j < (int)(2); ++j) {
      int num = ct[j] - must[j];
      int mx = rem / x[j];
      num = min(num, mx);
      rem -= num * x[j];
      tmp += num;
    }
    ans = max(ans, tmp);
  }
  return ans;
}
int main() {
  int t;
  scanf(" %d", &t);
  while (t--) printf("%d\n", solve());
  return 0;
}
