#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 1e5 + 10;
void solve() {
  long long n, t, a, b;
  cin >> n >> t >> a >> b;
  vector<pair<long long, long long> > v(n);
  vector<pair<long long, long long> > v2(n);
  long long e = 0, h = 0;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    v[i].second = x;
    if (x == 0)
      e++;
    else
      h++;
  }
  for (int i = 0; i < n; i++) {
    cin >> v[i].first;
  }
  sort(v.begin(), v.end());
  long long tr = 0;
  long long max = 0;
  long long sum = 0;
  tr = v[0].first - 1;
  long long temp = 0;
  if (tr >= a) {
    temp = temp + min(tr / a, e);
    tr = tr - min((tr / a) * a, e * a);
    temp = temp + min(tr / b, h);
    tr = tr - min((tr / b) * b, h * b);
    if (temp > max) max = temp;
  }
  for (int i = 0; i < n; i++) {
    if (i != n - 1) {
      if (v[i + 1].first == v[i].first) {
        if (v[i].second == 0) {
          sum = sum + a;
          e--;
        } else {
          sum = sum + b;
          h--;
        }
        continue;
      }
    }
    if (v[i].second == 0) {
      sum = sum + a;
      e--;
    } else {
      sum = sum + b;
      h--;
    }
    long long tem = 0;
    if (i != n - 1) {
      long long num = 0;
      tem = v[i + 1].first - 1;
      long long rem = 0;
      long long e2 = e, h2 = h;
      if (sum <= tem) {
        rem = tem - sum;
        long long t1 = rem / a;
        num = i + 1;
        rem = rem - min(t1 * a, e2 * a);
        num = num + min(t1, e2);
        long long t2 = rem / b;
        rem = rem - min(t2 * b, h2 * b);
        num = num + min(t2, h2);
      }
      if (num > max) max = num;
    } else {
      tem = t;
      if (tem >= sum) max = n;
    }
  }
  cout << max << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int test = 1;
  cin >> test;
  while (test--) {
    solve();
  }
}
