#include <bits/stdc++.h>
using namespace std;
template <class T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U>
void _W(const pair<T, U> &x) {
  _W(x.first);
  putchar(' ');
  _W(x.second);
}
template <class T>
void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin()) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
int MOD = 1e9 + 7;
void ADD(long long &x, long long v) {
  x = (x + v) % MOD;
  if (x < 0) x += MOD;
}
const int SIZE = 1e6 + 10;
int calc(int t, int low1, int low2, int n1, int n2, int a, int b) {
  if (t <= 0) return 0;
  if ((long long)low1 * a + (long long)low2 * b > t) return 0;
  int res = low1 + low2;
  n1 -= low1;
  n2 -= low2;
  t -= low1 * a + low2 * b;
  int v = min(n1, t / a);
  res += v;
  t -= a * v;
  v = min(n2, t / b);
  res += v;
  return res;
}
void solve() {
  int n, T, a, b;
  R(n, T, a, b);
  vector<int> p(n);
  for (int i = 0; i < (n); ++i) R(p[i]);
  vector<int> gg[2];
  int mi = 1e9;
  for (int i = 0; i < (n); ++i) {
    int t;
    R(t);
    gg[p[i]].push_back(t);
    mi = min(mi, t);
  }
  for (int i = 0; i < (2); ++i) sort((gg[i]).begin(), (gg[i]).end());
  int it[2] = {};
  int an =
      calc(mi - 1, 0, 0, ((int)(gg[0]).size()), ((int)(gg[1]).size()), a, b);
  while (it[0] < ((int)(gg[0]).size()) || it[1] < ((int)(gg[1]).size())) {
    mi = 1e9;
    for (int i = 0; i < (2); ++i)
      if (it[i] < ((int)(gg[i]).size())) mi = min(mi, gg[i][it[i]]);
    for (int i = 0; i < (2); ++i) {
      if (it[i] < ((int)(gg[i]).size()) && mi == gg[i][it[i]]) {
        it[i]++;
      }
    }
    int t = T;
    for (int i = 0; i < (2); ++i) {
      if (it[i] < ((int)(gg[i]).size())) t = min(t, gg[i][it[i]] - 1);
    }
    an = max(an, calc(t, it[0], it[1], ((int)(gg[0]).size()),
                      ((int)(gg[1]).size()), a, b));
  }
  W(an);
}
int main() {
  int ___T;
  scanf("%d", &___T);
  for (int cs = 1; cs <= ___T; cs++) {
    solve();
  }
  return 0;
}
