#include <bits/stdc++.h>
using namespace std;
int ar[200005], type[200005], Time[200005];
char ch[200005];
int n, T, a, b;
void solve() {
  scanf("%d%d%d%d", &n, &T, &a, &b);
  int cnt1 = 0, cnt2 = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &type[i]);
    if (type[i] == 0)
      cnt1++;
    else
      cnt2++;
  }
  pair<int, int> p[n + 5];
  for (int i = 1; i <= n; i++) {
    scanf("%d", &Time[i]);
    p[i] = {Time[i], type[i]};
  }
  p[n + 1] = {T + 1, 0};
  sort(p + 1, p + n + 2);
  long long val1 = 0, val2 = 0;
  long long re = 0;
  for (int i = 1; i <= n + 1; i++) {
    long long need = val1 * a + val2 * b;
    long long parbo = p[i].first - 1 - need;
    if (parbo >= 0) {
      long long parbo_easy = min((cnt1 - val1), parbo / a);
      parbo -= parbo_easy * a;
      long long parbo_hard = min(cnt2 - val2, parbo / b);
      re = max(re, val1 + val2 + parbo_easy + parbo_hard);
    }
    int j = i;
    while (j <= n + 1 && p[j].first == p[i].first) {
      if (p[j].second)
        val2++;
      else
        val1++;
      j++;
    }
    i = j - 1;
  }
  printf("%lld\n", re);
}
int main() {
  int t = 1;
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}
