#include <bits/stdc++.h>
using namespace std;
const int N = (int)3e5 + 5;
int n, T;
int task[N], tim[N], a[2], x[2], cnt[2];
int get_greedy(int T, int c0, int c1) {
  int get0 = min(c0, T / a[0]);
  T -= a[0] * get0;
  int get1 = min(c1, T / a[1]);
  T -= a[1] * get1;
  return get0 + get1;
}
void solve() {
  int ans = 0;
  long long all = 0;
  scanf("%d %d %d %d", &n, &T, &a[0], &a[1]);
  x[0] = x[1] = cnt[0] = cnt[1] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", task + i);
    cnt[task[i]]++;
  }
  vector<pair<int, int> > v;
  for (int i = 1; i <= n; i++) {
    int t;
    scanf("%d", &t);
    all += a[task[i]];
    v.push_back(make_pair(t, task[i]));
  }
  if (all <= T) {
    printf("%d\n", n);
    return;
  }
  sort((v).begin(), (v).end());
  if (v[0].first > 0) ans = get_greedy(v[0].first - 1, cnt[0], cnt[1]);
  v.push_back(make_pair(T + 1, 2));
  for (int i = 0; i + 1 < n; i++) {
    int j = i;
    x[v[i].second]++;
    while (j + 1 < n && v[i].first == v[j + 1].first) {
      j++;
      x[v[j].second]++;
    }
    i = j;
    long long required = (long long)x[0] * a[0] + (long long)x[1] * a[1];
    int nxtT = v[i + 1].first;
    if (required >= nxtT) {
      continue;
    }
    int rem = nxtT - required - 1;
    int la = cnt[0] - x[0];
    int lb = cnt[1] - x[1];
    int ans1 = x[0] + x[1] + get_greedy(rem, la, lb);
    ans = max(ans, ans1);
  }
  printf("%d\n", ans);
}
int main() {
  int m;
  scanf("%d", &m);
  while (m--) {
    solve();
  }
  return 0;
}
