#include <bits/stdc++.h>
using namespace std;
const long long int N = 2e5 + 5, mod = 31, bit = 60;
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int pro = 1, temp, t, i, j, l, r, n, m, x, y, z, mid, k, rem,
                carry = 0, ind, ans = 0, mx = -LONG_LONG_MAX,
                mn = LONG_LONG_MAX, cnt = 0, curr = 0, prev, next, sum = 0,
                i1 = -1, i2 = -1;
  cin >> t;
  long long int total, a, b, hard, easy, fine, finh, exte, exth, req, s, lh, le;
  while (t--) {
    hard = easy = 0;
    cin >> n >> total >> a >> b;
    bool type[n + 1];
    for (i = 1; i <= n; i++) {
      cin >> type[i];
      if (type[i]) {
        hard++;
      } else {
        easy++;
      }
    }
    vector<pair<long long int, long long int> > v;
    for (i = 1; i <= n; i++) {
      cin >> x;
      v.push_back({x, type[i]});
    }
    v.push_back({total + 1, 0});
    sort(v.begin(), v.end());
    fine = 0;
    finh = 0;
    ans = 0;
    j = 0;
    for (i = 0; i <= n; i++) {
      s = v[i].first - 1;
      while (j <= n and v[j].first <= s) {
        if (v[j].second) {
          finh++;
        } else {
          fine++;
        }
        j++;
      }
      req = finh * b + fine * a;
      if (s >= req) {
        rem = s - req;
        lh = hard - finh;
        le = easy - fine;
        exte = min(le, rem / a);
        rem -= (exte * a);
        exth = min(lh, rem / b);
        ans = max(ans, finh + fine + exte + exth);
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
