#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\n";
  err(++it, args...);
}
const double PI = acos(-1);
const double eps = (1e-9);
const long long int INF = 2e9;
const int M = (1e9) + 7;
const int N = (1e6) + 5;
int remaining(int time, int p, int q, int a, int b) {
  if (time < 0) return 0;
  int c = min(time / a, p);
  time -= (c * a);
  int d = min(time / b, q);
  return c + d;
}
void solve() {
  int n, t, i;
  scanf("%d%d", &n, &t);
  long long int a, b;
  cin >> a >> b;
  vector<pair<int, int> > vp(n);
  long long int p = 0, q = 0;
  for (i = 0; i < n; ++i) scanf("%d", &vp[i].second), q += vp[i].second;
  p = n - q;
  for (i = 0; i < n; ++i) scanf("%d", &vp[i].first);
  sort(vp.begin(), vp.end());
  vp.emplace_back(t + 1, 2);
  long long int x = 0, y = 0;
  int ans = remaining(vp[0].first - 1, p, q, a, b);
  long long int temp;
  for (i = 0; i < n; ++i) {
    if (vp[i].second == 0)
      x++;
    else
      y++;
    temp = x * a + y * b;
    if (temp < vp[i + 1].first)
      ans = max(ans,
                (int)x + (int)y +
                    remaining(vp[i + 1].first - temp - 1, p - x, q - y, a, b));
  }
  vp.clear();
  printf("%d\n", ans);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
}
