#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> a[200005];
void solve() {
  long long n, tim, cost[2], cnt[2] = {0, 0};
  cin >> n >> tim >> cost[0] >> cost[1];
  for (long long i = 0; i < n; i++) cin >> a[i].second, cnt[a[i].second]++;
  for (long long i = 0; i < n; i++) cin >> a[i].first;
  sort(a, a + n);
  a[n].first = tim + 1, a[n].second = 0;
  n++;
  long long ans = 0, sum = 0;
  for (long long i = 0; i < n; i++) {
    long long curans = i;
    long long tmp = a[i].first - 1;
    tmp -= sum;
    if (tmp < 0) {
      sum += cost[a[i].second];
      cnt[a[i].second]--;
      continue;
    }
    long long x = min(cnt[0], tmp / cost[0]);
    curans += x;
    tmp -= x * cost[0];
    x = min(cnt[1], tmp / cost[1]);
    curans += x;
    ans = max(ans, curans);
    sum += cost[a[i].second];
    cnt[a[i].second]--;
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
