#include <bits/stdc++.h>
using namespace std;
struct pt {
  long long c, t;
};
pt a[200002];
bool cmp(pt a, pt b) { return a.t < b.t; }
long long q, n, T, x, y, i, t0, sum, kq;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> q;
  while (q--) {
    cin >> n >> T >> x >> y;
    t0 = 0;
    for (i = 1; i <= n; i++) {
      cin >> a[i].c;
      t0 += 1 - a[i].c;
    }
    for (i = 1; i <= n; i++) cin >> a[i].t;
    sort(a + 1, a + n + 1, cmp);
    kq = 0;
    a[n + 1] = {0, T + 1};
    sum = 0;
    for (i = 0; i <= n; i++) {
      if (i > 0) {
        t0 -= (1 - a[i].c);
        if (a[i].c == 0)
          sum += x;
        else
          sum += y;
      }
      if (i < n && a[i + 1].t == a[i].t) continue;
      int l = 0, r = n - i;
      while (l < r) {
        long long mid = (l + r + 1) >> 1;
        long long tg;
        if (mid <= t0)
          tg = mid * x;
        else
          tg = t0 * x + (mid - t0) * y;
        if (tg + sum < a[i + 1].t)
          l = mid;
        else
          r = mid - 1;
      }
      long long tg;
      if (l <= t0)
        tg = l * x;
      else
        tg = t0 * x + (l - t0) * y;
      if (tg + sum < a[i + 1].t) kq = max(kq, i + l);
    }
    cout << kq << '\n';
  }
}
